Skip to content

Commit

Permalink
🐛 fix service worker caching on github pages
Browse files Browse the repository at this point in the history
  • Loading branch information
russkyc committed Jan 11, 2025
1 parent 0207c46 commit 7b64793
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions Russkyc.Timely/wwwroot/service-worker.published.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,16 @@ async function onActivate(event) {
async function onFetch(event) {
let cachedResponse = null;
if (event.request.method === 'GET') {
// For all navigation requests, try to serve index.html from cache
// For all navigation requests, try to serve index.html from cache,
// unless that request is for an offline resource.
// If you need some URLs to be server-rendered, edit the following check to exclude those URLs
const shouldServeIndexHtml = event.request.mode === 'navigate';
const shouldServeIndexHtml = event.request.mode === 'navigate'
&& !manifestUrlList.some(url => url === event.request.url);

const request = shouldServeIndexHtml ? 'index.html' : event.request;
const cache = await caches.open(cacheName);
cachedResponse = await cache.match(request);

if (cachedResponse && cachedResponse.redirected) {
cachedResponse = new Response(cachedResponse.body,
{
headers: cachedResponse.headers,
status: cachedResponse.status,
statusText: cachedResponse.statusText
});
}
}

return cachedResponse || fetch(event.request);
}
}

0 comments on commit 7b64793

Please sign in to comment.