我使用 sw-toolbox 库来编写 service worker。我的 PWA 缓存除 API 查询以外的所有内容(图片、CSS、JS、HTML)。但如果某些文件有一天被更改了怎么办?或者如果 service-worker.js 被更改了怎么办?应用程序应该如何检测文件的更改?
我的 service-worker.js:
'use strict';
importScripts('./build/sw-toolbox.js');
self.toolbox.options.cache = {
name: 'ionic-cache'
};
// pre-cache our key assets
self.toolbox.precache(
[
'./build/main.js',
'./build/main.css',
'./build/polyfills.js',
'index.html',
'manifest.json'
]
);
// dynamically cache any other local assets
self.toolbox.router.any('/*', self.toolbox.cacheFirst);
// for any other requests go to the network, cache,
// and then only use that cached resource if your user goes offline
self.toolbox.router.default = self.toolbox.networkFirst;
我不知道在PWA中更新缓存的常规方法。也许PWA应该在后台发送AJAX请求并检查UI版本?