// service-worker.js
self.addEventListener('fetch', (event) => {
// We have to duplicate a request
// as it cannot be consumed twice.
const duplicatedRequest = event.request.clone();
event.respondWith(fetch(event.request).catch(err => {
console.log(
"Fetch failed. Trying to retrieve cache data.",
err
);
return caches.match(duplicatedRequest);
}));
});