在Facebook Mobile Browser中单击链接可打开serviceworker指定的脱机文件。
我们已经在我们的网站上部署了一个服务工作人员,如果该网站处于离线状态,则会从缓存中加载html页面。
我尝试卸载serviceworker,但应用内浏览器仍会加载离线页面
我们的服务人员看起来很关注
//This is the "Offline page" service worker
//Install stage sets up the offline page in the cache and opens a new cache
self.addEventListener('install', function(event) {
var offlinePage = new Request('/CMSContent/Pages/Offline.html');
event.waitUntil(
fetch(offlinePage).then(function(response) {
return caches.open('sw-offline').then(function(cache) {
return cache.put(offlinePage, response);
});
}));
});
//If any fetch fails, it will show the offline page.
//Maybe this should be limited to HTML documents?
self.addEventListener('fetch', function(event) {
event.respondWith(
fetch(event.request).catch(function (error) {
return caches.open('sw-offline').then(function(cache) {
return cache.match('/CMSContent/Pages/Offline.html');
});
}
));
});
//This is a event that can be fired from your page to tell the SW to update the offline page
self.addEventListener('refreshOffline', function(response) {
return caches.open('sw-offline').then(function(cache) {
return cache.put(offlinePage, response);
});
});
在Facebook App中单击链接时,它将加载脱机页面。