fix: guard service-worker runtime cache on res.ok/basic + waitUntil

This commit is contained in:
2026-07-20 14:25:07 +01:00
parent 539798f8d0
commit b4fdb969a1
+4 -2
View File
@@ -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')))
);