我是服务人员和工作箱的新手。我目前正在使用工作箱来预缓存我的静态资产文件,它工作正常,我希望我的其他第三方 URL 在运行时也被缓存,但直到我在页面上第二次重新加载时才工作:(
下面显示的是我的 Service Worker 的代码副本,请注意我故意替换了我原来的 abc.domain.com 链接:)
workbox.routing.registerRoute(
//get resources from any abc.domain.com/
new RegExp('^https://abc.(?:domain).com/(.*)'),
/*
*respond with a cached response if available, falling back to the network request if it’s not cached.
*The network request is then used to update the cache.
*/
workbox.strategies.staleWhileRevalidate({
cacheName: 'Bill Resources',
maxEntries: 60,
maxAgeSeconds: 30 * 24 * 60 * 60, // 30 Days
}),
);
workbox.routing.registerRoute(
new RegExp('^https://fonts.(?:googleapis|gstatic).com/(.*)'),
//serve from network first, if not availabe then cache
workbox.strategies.networkFirst(),
);
workbox.routing.registerRoute(
new RegExp('^https://use.(?:fontawesome).com/(.*)'),
//serve from network first, if not availabe then cache
workbox.strategies.networkFirst(),
);
我已经清除了没有数字的存储时间,我从谷歌开发者工具中刷新了缓存存储,但一切似乎都是一样的。来自自定义链接、google fonts 和 fontawesome 的资源第一次无法缓存。下面是我的页面第一次加载图像和第二次加载图像的控制台和缓存存储选项卡。
请我不知道我做错了什么以及为什么会这样。
提前致谢