我尝试在服务工作者上渲染脱机页面,该页面在我的本地主机上运行良好,但是显然在我的实时服务器上不起作用,而且我没有收到任何错误
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
});
});
}
})
);
在活动服务器上,不呈现脱机页面,而当前请求保持呈现
答案 0 :(得分:0)
确保最后一个'。实际上是“ .php”,可能是site.com/site,而com / site在
上不匹配if(extention === 'php' || extention === '')
所以改用它,对我有用
if(extention === /php/.test(extention) || extention == 'htaccess' || extention === '' || /com/.test(extention))