简体   繁体   English

服务工作者不会在'/'上缓存golang服务器提供的index.html

[英]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.

相关问题 从 create-react-app 中的 service worker 缓存中排除 index.html - exclude index.html from service worker cache in create-react-app 服务工作者仅在添加“ index.html”时从缓存中获取URL。 - Service worker only fetches url from cache when adding “index.html” 如何使用服务人员处理 index.html 文件的缓存? - How to handle caching of index.html file with service worker? django提供的index.html无法找到socket.io服务器 - index.html served by django cant locate socket.io server grunt-contrib-connect不提供“ index.html” - “index.html” is not served by grunt-contrib-connect 在位于 SRC 文件夹中的 index.html 文件中注册 service-worker - ReactJS - Register a service-worker in index.html file that's located in SRC folder - ReactJS build/index.html 是否可以用作没有服务器的独立网页? - Does build/index.html serve as a standalone webpage without server? Ubuntu服务器不将外部文件链接到index.html - Ubuntu server does not link external files to index.html 如何清除浏览缓存 - index.html 卡在缓存中 - How to purge browse cache - index.html stuck in cache 如何将index.html中的变量传递给服务? - How to pass a variable in index.html to a service?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM