对 Service Worker 的长时间等待请求

编程入门 行业动态 更新时间:2024-10-27 19:20:24
本文介绍了对 Service Worker 的长时间等待请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我注意到等待 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 的长时间等待请求

本文发布于:2023-11-04 01:28:29,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1556575.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:长时间   Service   Worker

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!