Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 服务人员缓存不’;t更新_Javascript_Caching_Service Worker_Progressive Web Apps - Fatal编程技术网

Javascript 服务人员缓存不’;t更新

Javascript 服务人员缓存不’;t更新,javascript,caching,service-worker,progressive-web-apps,Javascript,Caching,Service Worker,Progressive Web Apps,我正在尝试在ServiceWorker中缓存静态资产。但是当我编辑一些静态文件并关闭选项卡并再次打开它时,我看不到任何更改 我的缓存没有更新。如果我清除ChromeWebTools中的站点数据并重新打开选项卡,我会看到新的更改 请看下面我的代码 self.addEventListener('install', function(event) { event.waitUntil( caches.open('static') .then(function(cache) {

我正在尝试在ServiceWorker中缓存静态资产。但是当我编辑一些静态文件并关闭选项卡并再次打开它时,我看不到任何更改

我的缓存没有更新。如果我清除ChromeWebTools中的站点数据并重新打开选项卡,我会看到新的更改

请看下面我的代码

self.addEventListener('install', function(event) {
  event.waitUntil(
    caches.open('static')
      .then(function(cache) {
        cache.addAll([
            '/index.html',
            '/src/js/app.js',
            '/src/css/app.css'
        ]);
     })
  );
});

self.addEventListener('fetch', function(event) {
   event.respondWith(
     caches.match(event.request)
   );
});

使用Google Chrome,尝试按Ctrl+Shift+I,单击应用程序,然后单击服务人员。在此选项卡中,您可以取消注册您想要的任何工作人员

您应该使用缓存版本控制

var STATIC_CACHE_VERSION = '1';
每次更改
STATIC\u cache\u VERSION
变量时,下面的函数将刷新缓存

self.addEventListener('activate', function(event) {
  event.waitUntil(
    caches.keys()
      .then(function(keyList) {
        return Promise.all(keyList.map(function(key) {
          if (key !== 'static-' + STATIC_CACHE_VERSION) {
            return caches.delete(key);
          }
        }));
      })
  );
  return self.clients.claim();
});

另一个选项是按Ctrl+Shift+R在不缓存的情况下重新加载选项卡