我是工作箱中的新手,当我脱机并刷新页面时,它变为空白,这有时会清除缓存数据,有时会存在该数据。我正在使用stalewhilerevalidate策略。我需要在下面的代码中添加更多内容吗?据我所知,知识盒策略可以处理所有事件。当我访问我的网站一段时间后,一切正常,刷新后页面会显示。
sw.js
workbox.setConfig({
debug: false
});
workbox.skipWaiting();
workbox.clientsClaim();
let BASE_URL = location.protocol + "//" + location.host,
API_URL = BASE_URL + '/xy/xyz/xy/',
CURRENTLY_AUTHENTICATED = API_URL + 'account/check-account'
workbox.precaching.precacheAndRoute(self.__precacheManifest || []);
workbox.precaching.suppressWarnings();
workbox.routing.registerRoute(/.*(?:googleapis|gstatic)\.com.*$/, workbox.strategies.staleWhileRevalidate({
cacheName: 'google-fonts'
}));
workbox.routing.registerRoute(CURRENTLY_AUTHENTICATED, workbox.strategies.networkFirst({
cacheName: 'CURRENTLY_AUTHENTICATED'
}));
workbox.routing.registerRoute(
new RegExp('/xy-xyz/'),
workbox.strategies.staleWhileRevalidate({
cacheName: 'cache-name',
plugins: [
new workbox.expiration.Plugin({
maxEntries: 20,
maxAgeSeconds: 24 * 60 * 60
}),
new workbox.broadcastUpdate.Plugin('cache-name', {
headersToCheck: ['date'],
})
]
}));
// whitelist and blacklist for specific request
workbox.routing.registerNavigationRoute("index.html", {
cacheName: "app-shell",
whitelist: [],
blacklist: []
});