【发布时间】:2019-01-04 20:43:11
【问题描述】:
我有一个网站,我在根目录安装了一个服务工作者,甚至将范围设置为“/”,如此处所述:Service worker is caching files but fetch event is never fired
但是,fetch 事件没有触发。任何帮助表示赞赏。
importScripts('/site/themes/libs/cache-polyfill.js');
self.addEventListener('install', function (e) {
e.waitUntil(
caches.open('v1').then(function (cache) {
return cache.addAll([
'/',
'/test-page',
'/site/themes/css/main.css',
'/site/themes/js/vendors.min.js',
'/site/themes/js/app.min.js'
]);
})
);
self.skipWaiting()
});
self.addEventListener('fetch', function (event) {
console.log(event.request.url);
event.respondWith(
caches.match(event.request).then(function (response) {
return response || fetch(event.request);
})
);
});
编辑: 我正在为网站使用 statamic。
【问题讨论】:
-
您的域不是
localhost,但不是https://? -
我在 localhost 上尝试,我应该在 https 上部署和测试它吗? @WilliamChong
-
localhost应该没问题,那就和https无关 -
@WilliamChong 我使用statamic 的事实可能是问题吗?
-
statamic 是否会影响您的
localhost,您的问题是否出现在localhost下?不熟悉
标签: javascript service-worker statamic