diff --git a/static/js/sw.js b/static/js/sw.js index d52308e..bb6afc0 100644 --- a/static/js/sw.js +++ b/static/js/sw.js @@ -2,10 +2,9 @@ * diora service worker — caches the app shell for offline use. */ -const CACHE = 'diora-v3'; +const CACHE = 'diora-v4'; const PODCAST_CACHE = 'diora-podcast-v1'; const SHELL = [ - '/', '/static/css/app.css', '/static/js/app.js', '/static/manifest.json', @@ -72,19 +71,13 @@ self.addEventListener('fetch', function (event) { return; } - event.respondWith( - caches.match(event.request).then(function (cached) { - if (cached) return cached; - return fetch(event.request).then(function (response) { - // Cache successful GET responses for shell assets - if (response && response.status === 200 && response.type === 'basic') { - const clone = response.clone(); - caches.open(CACHE).then(function (cache) { - cache.put(event.request, clone); - }); - } - return response; - }); - }) - ); + // Cache-first only for pre-defined shell assets; everything else hits the network + const isShell = SHELL.some(function (s) { return url.pathname === s; }); + if (isShell) { + event.respondWith( + caches.match(event.request).then(function (cached) { + return cached || fetch(event.request); + }) + ); + } });