如果翻译被缓存,您需要将其更改cacheName
为您的服务工作者激活。
IE:
var cacheName = 'myAppCache-3s';
var filesToCache = [
'/'
'index.html',
'scripts/hammer.min.js',
'images/play_white.svg',
'images/stop_white.svg',
'images/back_white.svg',
'images/forward_white.svg',
'images/sfondo.jpg',
'images/ic_refresh_white_24px.svg',
'scripts/meteo-zoom.js',
'scripts/meteosurf_200.js',
'scripts/jquery3-2-1.min.js',
'scripts/jqueryui1-12-1.min.js',
'styles/inline_01.css',
'styles/meteosurf_200.css',
'styles/jqueryui-smoothness.css',
'styles/images/ui-bg_glass_65_ffffff_1x400.png',
'styles/images/ui-icons_454545_256x240.png',
'images/icons/icon-64x64.png',
];
当我更改资产时,我总是更改缓存名称,在名称末尾添加一个新版本(即:)var cacheName = 'myAppCache-3t';
。
如果您的 Service Worker 之前已安装,但在刷新或页面加载时有新版本的 Worker 可用,则新版本会在后台安装,但尚未激活。仅当不再加载任何仍在使用旧服务工作者的页面时才会激活它。一旦不再加载此类页面,新的 service worker 就会激活。
但是您可以使用以下函数强制执行此行为skipWaiting()
:
self.addEventListener('install', function(e) {
console.log('[ServiceWorker] Install');
e.waitUntil(
caches.open(cacheName).then(function(cache) {
console.log('[ServiceWorker] Caching app shell');
return cache.addAll(filesToCache);
}).then(function() {
return self.skipWaiting();
})
);
});