我正在使用PWABuilder的一名服务人员为我的网站https://digimoncard.io/服务。
缓存第一网络服务工作者JS文件包含以下代码:
// This is the service worker with the Cache-first network
const CACHE = "pwabuilder-precache";
importScripts('https://storage.googleapis.com/workbox-cdn/releases/5.0.0/workbox-sw.js');
self.addEventListener("message", (event) => {
if (event.data && event.data.type === "SKIP_WAITING") {
self.skipWaiting();
}
});
workbox.routing.registerRoute(
new RegExp('/*'),
new workbox.strategies.CacheFirst({
cacheName: CACHE
})
);然后,在正文下面的index.php文件中有以下代码:
<!-- PWA -->
<script type="module">
import 'https://cdn.jsdelivr.net/npm/@pwabuilder/pwaupdate';
const el = document.createElement('pwa-update');
document.body.appendChild(el);
</script>
<!-- END PWA -->服务人员似乎从来没有更新过?不管我在任何页面上更改了什么(内容、文件版本控制等),如果服务器工作人员已经是缓存,则不会进行更新。我可以通过清除浏览器缓存来手动修复这个问题,但是我要么遗漏了什么,要么这就是我想要的?例如,我在手机上访问的版本已经过时2天了。
发布于 2020-05-19 14:22:43
这是使用缓存优先策略时的预期行为。假设缓存中有匹配项,则将使用该响应。
如果您正在寻找“如果存在的话使用缓存响应,但也要在后台更新它”的方法,您可以切换到陈旧的同时重新验证策略。
工作框外支持的策略的完整列表可在https://developers.google.com/web/tools/workbox/modules/workbox-strategies中找到。
https://stackoverflow.com/questions/61890390
复制相似问题