implement fix for strange first load cache behavior

This commit is contained in:
Arthur Lu 2022-12-01 08:09:22 +00:00
parent d95f0036ac
commit 1ed46b8ade

View File

@ -34,12 +34,15 @@ self.addEventListener("install", async () => {
});
self.addEventListener("fetch", (event) => {
console.log(`fetching: ${event.request.url}`);
event.respondWith(caches.open(CACHE_NAME).then((cache) => {
return fetch(event.request).then((fetchedResponse) => {
cache.put(event.request, fetchedResponse.clone());
console.log(typeof(fetchedResponse));
return fetchedResponse;
}).catch(() => {
return cache.match(event.request);
console.log(cache.match(event.request, {ignoreVary: true}));
return cache.match(event.request, {ignoreVary: true});
});
}));
});