From f42b1b313c35677369132641227cec80b6c50f7a Mon Sep 17 00:00:00 2001 From: ayoayco Date: Fri, 2 Aug 2024 16:20:44 +0200 Subject: [PATCH] feat: don't cache missing file --- public/sw.js | 14 +++++++++----- src/pages/index.astro | 26 +++++++++++++++++++++----- 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/public/sw.js b/public/sw.js index 797f73a..2fcbc7d 100644 --- a/public/sw.js +++ b/public/sw.js @@ -1,10 +1,12 @@ const addResourcesToCache = async (resources) => { - const cache = await caches.open('v1'); + const cache = await caches.open('cozy-reader-app-v1'); + console.log('adding resources to cache...', resources) await cache.addAll(resources); }; const putInCache = async (request, response) => { - const cache = await caches.open('v1'); + const cache = await caches.open('cozy-reader-app-v1'); + console.log('adding one response to cache...', request) await cache.put(request, response); }; @@ -59,25 +61,27 @@ const enableNavigationPreload = async () => { }; self.addEventListener('activate', (event) => { + console.log('activating...', event) event.waitUntil(enableNavigationPreload()); }); self.addEventListener('install', (event) => { + console.log('installing...', event) event.waitUntil( addResourcesToCache([ './', - './index.html', - './favicon.ico' + './favicon.ico', ]) ); }); self.addEventListener('fetch', (event) => { + console.log('fetch happened', event.request) event.respondWith( cacheFirst({ request: event.request, preloadResponsePromise: event.preloadResponse, - fallbackUrl: './index.html', + fallbackUrl: './', }) ); }); \ No newline at end of file diff --git a/src/pages/index.astro b/src/pages/index.astro index c455713..3c8727f 100644 --- a/src/pages/index.astro +++ b/src/pages/index.astro @@ -40,10 +40,26 @@ if (url) \ No newline at end of file