[英]Service Worker Offline when Browser Back (requires Refresh)
My service worker is really simple; 我的服务人员非常简单; just a method for caching fonts, JS, and a few other items to accelerate page performance and reduce data transfer.
只是一种用于缓存字体,JS和其他一些项目的方法,以加快页面性能并减少数据传输。
However, when live ( example ) navigating to a second page then using the browser's back button displays the OFFLINE page rather than TRYing first or using the natural browser cache. 但是,当实时( 示例 )导航到第二页时,然后使用浏览器的后退按钮显示OFFLINE页面,而不是先尝试或使用自然浏览器缓存。
Relevant part of SW: SW的相关部分:
// Clear old caches when activated
self.addEventListener('activate', function(e) {
e.waitUntil(
caches.keys().then(function(keyList) {
return Promise.all(keyList.map(function(key) {
if (key !== cacheName) {
console.log('[ServiceWorker] Removing old cache', key);
return caches.delete(key);
}
}));
})
);
return self.clients.claim();
});
self.addEventListener('fetch', function(event) {
event.respondWith(
// Try the cache
caches.match(event.request).then(function(response) {
// Fall back to network
return response || fetch(event.request);
}).catch(function() {
// If both fail, show a generic fallback:
return caches.match('/offline.htm');
// However, in reality you'd have many different
// fallbacks, depending on URL & headers.
// Eg, a fallback silhouette image for avatars.
})
);
});
This seems more likely (or possibly isolated to) Firefox (current version 59.0.2). 这似乎更可能(或可能仅限于Firefox)(当前版本59.0.2)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.