fix: guard service-worker runtime cache on res.ok/basic + waitUntil
This commit is contained in:
+4
-2
@@ -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')))
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user