[英]Service worker does not cache index.html served by golang server on '/'
I'm playing around with a service worker trying to cache my index.html. 我正在和一个服务人员一起尝试缓存我的index.html。 I'm serving it via
我通过
http.HandleFunc("/sw", handle.SW)
http.HandleFunc("/", handle.Index)
My service worker cache looks like this 我的服务工作者缓存看起来像这样
self.addEventListener('install', (event) => {
self.skipWaiting();
event.waitUntil(async function () {
const cache = await caches.open(CACHE_VERSION);
await cache.addAll([
'/',
'/static/merged.css',
'/static/merged.js',
'/favicon.ico'
]);
}());
});
Without the service worker my network tab in the developer tools shows the size of the index.html with 4.5 KB and a time of 46ms. 如果没有服务工作者,开发人员工具中的“我的网络”标签会显示index.html的大小,大小为4.5 KB,时间为46ms。
Now with the service worker merged.css, merged.js and favicon.ico are cached, but my index has two entries. 现在,通过服务工作者merged.css,merged.js和favicon.ico被缓存,但是我的索引有两个条目。 One from service worker, and one of size 4.5 KB and a time of 48ms.
一个来自服务工作者,另一个大小为4.5 KB,时间为48ms。
So I'm guessing that index.html is not cached and I can not find out how to do it. 因此,我猜测index.html没有被缓存,并且我不知道该怎么做。
From the screenshot you uploaded, it says that the request for fetching the index.html is initiated by a script named sw.js, and the exact code is placed at the second line. 在您上传的屏幕截图中,它说获取index.html的请求是由名为sw.js的脚本发起的,确切的代码位于第二行。 If this is truly the service-worker in your code, please recheck it carefully and find out why this request is made.
如果这确实是您代码中的服务人员,请仔细检查一下并找出提出此请求的原因。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.