此处生成的代码
importScripts("https://storage.googleapis.com/workbox-cdn/releases/4.3.1/workbox-sw.js");
workbox.setConfig({
debug: true
});
workbox.precaching.precacheAndRoute([
{
"url": "/rest/resource/build.all.json",
"revision": "9d178a1ffe18be2bce92e19fe306416d"
},
{
"url": "/rest/resource/build.development.css",
"revision": "5ab54583dfad8742646fb861508fcc35"
},
{
"url": "/rest/resource/build.development.js",
"revision": "7a1e8c3842995311ff261d4c61019b9a"
},
{
"url": "/rest/resource/build.en.json",
"revision": "3d61d4813aee32b2923d641a31315038"
},
{
"url": "/rest/resource/build.es.json",
"revision": "0156fc3e3ce19ce1599637297a1e2c34"
},
{
"url": "/rest/resource/build.production.css",
"revision": "d735af4146c40622a86fa4fb0f98a189"
},
{
"url": "/rest/resource/build.production.js",
"revision": "66ff9441978be021d9266c85d2dcdf5f"
},
{
"url": "/rest/resource/cache-worker.development.js",
"revision": "7bb4f72279b7dcabed44bc64aeb8c31f"
},
{
"url": "/rest/resource/cache-worker.production.js",
"revision": "85dc9271fa5116b22427bec55a363ed1"
},
{
"url": "/rest/resource/es.moment.js",
"revision": "0c22f2804c5531dcffd6645db0c29f3d"
},
{
"url": "index.html",
"revision": "ecc5d5effdf0bed580f7f690dbb1659e"
},
{
"url": "/rest/resource/lang.json",
"revision": "d03767404afe4cfb994f4a968d3dbdb9"
},
{
"url": "/rest/resource/terms_and_conditions/en.html",
"revision": "3c5e6f698cc4b73027fb376ee5c681c9"
},
{
"url": "/rest/resource/terms_and_conditions/es.html",
"revision": "6c22a15d10216f293b0658417b7a1b9a"
}
],
{
// Ignore all URL parameters.
ignoreURLParametersMatching: [/.*/],
},
);
workbox.routing.registerNavigationRoute(
workbox.precaching.getCacheKeyForURL('index.html'), {
blacklist: [
new RegExp('/rest/uploads/'),
new RegExp('/rest/util/'),
new RegExp('/rest/autocomplete/'),
new RegExp('/rest/autocomplete-check/'),
new RegExp('/rest/index-check/'),
new RegExp('/graphql/'),
],
}
);
我可以看到正在生成缓存,文件已正确存储在缓存中。
在该工作箱停止执行任何操作之后,甚至不再匹配文件。
我希望至少每次服务器调用来获取/rest/resources/build.en.json文件时,workbox实际上都会返回文件,但是这种情况永远不会发生,workbox甚至都不再记录消息了,不检查,只是保持沉默。
它也永远不会匹配索引,这是SPA,不是url资源,并且不在指定文件夹中的内容都应提供索引,但这也不起作用。
答案 0 :(得分:0)
切换到普通服务工作者之后(没有工作箱),我设法弄清楚了它的原因,因为这是工作者的范围,没有像在子文件夹中那样考虑根目录。
基本上,工作进程位于dist/worker.js
中,而不位于worker.js
中,这意味着获取事件并未触发/resources
我将继续使用普通的工作程序,因为它们更易于调试,但是对于那些可能存在类似问题的人,这可以作为参考。