From b4fdb969a1717b6d7b3b476edd23bbe2ace6a106 Mon Sep 17 00:00:00 2001 From: Tim Evans Date: Mon, 20 Jul 2026 14:25:07 +0100 Subject: [PATCH] fix: guard service-worker runtime cache on res.ok/basic + waitUntil --- public/sw.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/public/sw.js b/public/sw.js index c00c30b..6a9bfd6 100644 --- a/public/sw.js +++ b/public/sw.js @@ -14,8 +14,10 @@ self.addEventListener('fetch', (e) => { if (e.request.method !== 'GET') return; e.respondWith( caches.match(e.request).then((hit) => hit || fetch(e.request).then((res) => { - const copy = res.clone(); - caches.open(CACHE).then((c) => c.put(e.request, copy)); + if (res.ok && res.type === 'basic') { + const copy = res.clone(); + e.waitUntil(caches.open(CACHE).then((c) => c.put(e.request, copy))); + } return res; }).catch(() => caches.match('/index.html'))) );