我使用服務人員和sw-toolbox庫。我的PWA緩存除API查詢以外的所有內容(圖像,css,js,html)。但是如果某些文件有一天會改變,會怎樣呢?或者,如果service-worker.js將被更改。 應用程序應該如何知道文件中的更改?如何更新PWA中的服務工作者緩存?
我的服務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版本?