Serving Files with Network-First Policy
Let's replace the fetch
event handler in serviceworker.js
to use now the algorithm known as Network first.
self.addEventListener("fetch", async event => {
event.respondWith(
(async () => {
try {
const fetchResponse = await fetch(event.request);
return fetchResponse;
} catch (e) {
const cachedResponse = await caches.match(event.request);
if (cachedResponse) return cachedResponse;
}
})()
);
});