我在模板文件中添加了服务工作者和工作箱,如下所示:
<script type="text/javascript">
(function () {
if ('serviceWorker' in navigator) {
navigator.serviceWorker
.register('sw.js')
.then(function(registration) {
console.log('Service Worker registration successful with scope: ',
registration.scope);
})
.catch(function(err) {
console.log('Service Worker registration failed: ', err);
});
}
})();
</script>
在 sw.js 中,我有
importScripts('workbox-sw.prod.v2.1.2.js');
const workboxSW = new WorkboxSW();
if (workboxSW) {
console.log('Yay! workboxSW is loaded');
const staleWhileRevalidateStrategy = workboxSW.strategies.staleWhileRevalidate();
workboxSW.router.registerRoute('/*\.css/', staleWhileRevalidateStrategy);
} else {
console.log('Boo! workboxSW didn\'t load');
}
我可以在控制台日志中看到“Service Worker 注册成功”和“Yay!workboxSW 已加载”。但是我在缓存存储(应用程序->缓存存储)下看不到任何东西。如何更新它以便我可以看到服务人员的缓存内容?