I'm working with services worker and I have the following code
self.addEventListener('fetch', function (event) {
const url = new URL(event.request.url)
if (event.request.mode == "navigate") {
const fetchData = fetch(event.request).catch(function () {
//console.log("errr")
return caches.match("/core/index.php/offline_controlador/index")
});
event.respondWith(fetchData)
return;
}
event.respondWith(
caches.match(event.request).then(function (response) {
return response || fetch(event.request);
})
);
});
when i tried to get these files from the cache, it does not work, but when i change the code to
event.respondWith(
caches.match(event.request.url).then(function(response) {
return response || fetch(event.request);
})
);
instead of
event.respondWith(
caches.match(event.request).then(function(response) {
return response || fetch(event.request);
})
);
It works perfect