我尝试在我的服务人员上渲染一个离线页面,它在我的本地主机上运行良好,但显然它在我的实时服务器上不起作用,我没有收到任何错误
event.waitUntil(updateCache(event.request));
event.respondWith(
fetch(event.request).catch(function(error) {
//console.log( ' Network request Failed. Serving content from cache: ' + error );
//Check to see if you have it in the cache
//Return error page if file is document file else return failed
function fe(filename) {
return filename.slice((filename.lastIndexOf(".") - 1 >>> 0) + 2);
}
// Fetch the request extention
let extention = fe(event.request.url)
if(extention === 'php' || extention === ''){
console.log('rendering Offline')
// match offline only if request is for a page not an asset
return caches.match(offlineUrl);
}else{
console.log('Still searching: ' + extention)
return caches.open('saving-nest').then(function (cache) {
return cache.match(event.request).then(function (matching) {
var report = !matching || matching.status == 404?Promise.reject('no-match'): matching;
return report
});
});
}
})
);
在实时服务器上,不呈现离线页面,而是呈现当前请求