Skip to content

Commit

Permalink
Update serviceWorker.js
Browse files Browse the repository at this point in the history
  • Loading branch information
datajohnson committed May 31, 2024
1 parent 39f78f6 commit 929918b
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions web/public/serviceWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,22 @@ self.addEventListener("message", (event) => {
});

self.addEventListener("fetch", (event) => {
console.log("FETCH", event);
if (event.data && event.data.type === "SKIP_WAITING") {
self.skipWaiting();
}
console.log("FETCH", event.request);

event.respondWith(
fetch(event.request)
.then((cache) => {
return fetch(event.request).then(function (response) {
caches.open("basic").put(event.request, response.clone());
console.log("ADDING TO CACHE", event.request);
return response;
});
})
.catch((err) => {
console.log("RETURNING FROM CACHE", event.request, err);
return caches.match(event.request);
})
);
});

console.log("Loading serviceWorker.js");
Expand Down

0 comments on commit 929918b

Please sign in to comment.