我正在与服务人员一起工作,我有以下代码
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);
})
);
});
当我试图从缓存中获取这些文件时,它不起作用,但是当我将代码更改为
event.respondWith(
caches.match(event.request.url).then(function(response) {
return response || fetch(event.request);
})
);
代替
event.respondWith(
caches.match(event.request).then(function(response) {
return response || fetch(event.request);
})
);
它完美无缺