gpt4 book ai didi

Are service workers ever removed automatically by the browser?(服务人员是否会被浏览器自动删除?)

转载 作者:bug小助手 更新时间:2023-10-25 13:46:32 26 4
gpt4 key购买 nike



I've been trying to make PWAs that reliably work offline on and off for the past year, but every time I write a new service worker, it works as expected for a week or two and then just breaks (until reconnecting). I thought it was due to the site's data getting evicted, but the local storage is often intact when I reconnect to the internet so it can load. Recently I also had one of the service workers remain active, but its cache storage was deleted, as well as the other service workers (I've got multiple different sites on the same origin, some of which have service workers. It's my GitHub Pages).

在过去的一年里,我一直试图让PWA断断续续地可靠地脱机工作,但每次我编写一个新的服务工作者时,它都会像预期的那样工作一到两周,然后就会中断(直到重新连接)。我认为这是因为网站的数据被驱逐了,但当我重新连接到互联网以便可以加载时,本地存储通常是完好无损的。最近,我也让其中一个服务工作者保持活动状态,但其缓存存储已被删除,以及其他服务工作者(我在同一来源上有多个不同的站点,其中一些站点有服务工作者)。这是我的GitHub页面)。


According to the spec, it sounds like service workers should always remain registered unless the data for the whole origin is evicted. I also don't think my service workers are accidentally deleting their caches or unregistering themselves as the issue only happens after not using them for a while, in which case they aren't running. Clearing Chrome for Android's cache also doesn't break the PWAs when offline, so I don't think I'm manually doing anything that's breaking them. Clearing an individual PWA's storage and cache also doesn't break it.

根据该规范,听起来服务人员应该始终保持注册状态,除非整个来源的数据被驱逐。我也不认为我的服务人员不小心删除了他们的缓存或注销了自己,因为这个问题只有在一段时间不使用它们之后才会发生,在这种情况下,他们没有运行。清除Chrome的Android缓存也不会在离线时破坏PWAS,所以我不认为我手动做了任何破坏它们的事情。清除单个PWA的存储和缓存也不会破坏它。


The relevant sentence in the spec:

规范中的相关句子:



"A user agent must persistently keep a list of registered service worker registrations unless otherwise they are explicitly unregistered."



(the unregistered service workers also don't show up in chrome://serviceworker-internals/ )

(未注册的服务工作者也不会出现在Chrome://serviceWorker-interals/中)


Any ideas? Do you think this is a bug? I've mostly seen this in Chrome for Android, but I think I'll try some other browsers as well to check. Unfortunately I can't test any of this very well as it's quite unpredictable and takes weeks.

有什么主意吗?你觉得这是个窃听器吗?我主要在Chrome for Android上看到了这一点,但我想我也会尝试其他一些浏览器来检查一下。不幸的是,我不能很好地测试这一切,因为它非常不可预测,需要数周时间。


These are the 2 main sites to try, as I use the same template for a few, although I don't think it'll be that helpful:

以下是两个可以尝试的主要网站,因为我对一些网站使用了相同的模板,尽管我认为它不会有太大帮助:



Thanks for any input

感谢您的意见


Edit: I thought it would be worth a try to see if that first site still works in Firefox while offline. It does, despite not visiting it in Firefox for maybe 6 months. I guess this is a Chrome bug/feature then?

编辑:我认为值得一试,看看第一个站点在离线时是否还能在Firefox中运行。它确实是这样,尽管可能有6个月没有在Firefox中访问它。我猜这是Chrome的错误/功能吧?


Edit: Updated the title

编辑:更新了标题


更多回答
优秀答案推荐

7 months later and I finally have somewhat of an answer...

7个月后,我终于有了一些答案……


The browser keeps them more-or-less forever, in the same way it does with IndexedDB. The same is also true with resources stored with the Cache API, which has a similar bit in the spec:

浏览器或多或少永远保留它们,就像它对IndexedDB所做的那样。使用缓存API存储的资源也是如此,规范中也有类似的内容:



"The Cache instances are not part of the browser’s HTTP cache. The Cache objects are exactly what authors have to manage themselves. The Cache objects do not get updated unless authors explicitly request them to be. The Cache objects do not expire unless authors delete the entries. The Cache objects do not disappear just because the service worker script is updated. That is, caches are not updated automatically. Updates must be manually managed. This implies that authors should version their caches by name and make sure to use the caches only from the version of the service worker that can safely operate on."



Since getting a new phone and not encountering the issue, I suspect it's to do with the amount of available storage. Either what's happening is:

既然买了一部新手机,却没有遇到这个问题,我怀疑这与可用存储容量有关。要么是正在发生的事情是:



  • Chrome is breaking the spec and clearing certain parts of the site's storage, rather than evicting everything.

  • Some program is trying to be helpful by deleting this cache. But I don't think I installed an app that would do that and it seems unlikely that there's a preinstalled app that would do it.


Looking at those, I'd say the 1st is more likely, but it still doesn't make much sense. Surely there are many more sites to delete the data of first. Maybe Chrome has a process that clears just the cache storage when the device is running low? In any case, I'd probably have to read through the source code to find out.

考虑到这些,我会说第一次更有可能,但这仍然没有太大意义。当然,还有更多的网站需要删除First的数据。也许Chrome有一个进程,在设备运行不足时只清除缓存存储空间?在任何情况下,我都可能必须通读源代码才能找到答案。


I guess I'll also have to see if the issue reoccurs if and when I start to run out of storage on my new phone.

我想我还得看看,如果我的新手机的存储空间开始用完,这个问题是否会再次出现。


更多回答

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com