简体   繁体   English

浏览器返回时需要重新启动Service Worker(需要刷新)

[英]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)。

So Installed FF developer version 因此安装了FF开发人员版本

FF60

And it works fine in FF60 它在FF60中工作正常

FF60 FF60

工作中

The issue is with FF59.0 it seems FF59.0的问题似乎是

FF59 FF59

FF59

So most probably a issue that will be fixed with next update 因此最有可能在下次更新中解决的问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM