我注意到等待 Service Worker 响应缓存中的项目的时间并不像您预期的那么快.我在 sw-precache 和自定义编写的 Service Worker 中看到了相同的等待时间.
I have noticed that the time waiting for service workers to respond with items from the cache is not as fast as you would expect it to be. I have seen the same wait times with both sw-precache and a custom written service worker.
这个等待时间的可能原因是什么,我该如何减少它?
What are the possible causes for this wait time time and how could I reduce it?
我在自定义 Service Worker 上的 fetch 事件如下所示:
My fetch event on the custom service worker looks like:
self.addEventListener('fetch', function(event) { event.respondWith( caches.match(event.request).then(function(response) { if (response) { return response; } return fetch(event.request); }) ); }); 推荐答案您是否在 Chrome Dev Tools 中的 Application -> Service Worker 选项卡下选中了Update on reload"?
Do you have 'Update on reload' checked within your Chrome Dev Tools under the Application -> Service Worker tab?
如果是这样,那么我认为这可能是问题所在,因为它会重新运行您所有的 Service Worker 代码,当使用 sw-precache 时,这些代码可能是相当多的代码,在每个重新加载.
If so then I think this may be the problem as it'll be re-running all your Service Worker code, which can be quite a lot of code when using sw-precache, on each reload.
更多推荐
对 Service Worker 的长时间等待请求
发布评论