Skip to content

Commit

Permalink
Cache CSS using ServiceWorker given GitHub's deficiencies
Browse files Browse the repository at this point in the history
  • Loading branch information
guilhermesimoes committed Oct 18, 2024
1 parent 2826704 commit 693e962
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions service-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ async function fetchOrGoToOfflinePage(fetchEvent) {
);
}

// "hack" until GitHub pages supports a longer Cache-Control https://github.com/orgs/community/discussions/11884
if (eventRequest.url.endsWith('.css')) {
return Promise.all([fetch(eventRequest), caches.open(CACHE_NAME)]).then(
([response, cache]) => cache.add(eventRequest.url, response).then(() => response.clone()),
(error) => caches.match(eventRequest.url)
)
}

return fetch(eventRequest);
}

Expand Down

0 comments on commit 693e962

Please sign in to comment.