主屏幕添加 (A2H) 是否曾经是浏览器在存储空间不足时推迟 PWA 缓存清除的信号?

Is homescreen addition (A2H) ever a signal for browsers to defer PWA cache purging when storage runs low?

当浏览器的存储空间不足时 space,据我所知,它将从最近最少访问的站点开始清除站点 (PWA) 的缓存。每,Using the Cache API in the service worker

You are responsible for implementing how your script (service worker) handles updates to the cache. All updates to items in the cache must be explicitly requested; items will not expire and must be deleted. However, if the amount of cached data exceeds the browser's storage limit, the browser will begin evicting all data associated with an origin, one origin at a time, until the storage amount goes under the limit again. See Browser storage limits and eviction criteria for more information.

链接的驱逐标准包括关于 LRU policy 的部分:

When the available disk space is filled up, the quota manager will start clearing out data based on an LRU policy — the least recently used origin will be deleted first, then the next one, until the browser is no longer over the limit.

We track the "last access time" for each origin using temporary storage. Once the global limit for temporary storage is reached (more on the limit later), we try to find all currently unused origins (i.e., ones with no tabs/apps open that are keeping open datastores). These are then sorted according to "last access time." The least recently used origins are then deleted until there's enough space to fulfill the request that triggered this origin eviction.

现在的问题是:浏览器是否使用网站是否已添加到主屏幕 (A2H) 作为延迟清除给定网站缓存存储的信号? 对我来说浏览器优先清除访问最少的 非 A2H 站点缓存,然后再开始清除用户已明确给予特殊 A2H 指定的站点缓存,这似乎是合乎逻辑的。


Question originally asked in the context of the PWA feature plugin 用于 WordPress。

我不知道 "add to home screen" 在确定是否在设备 运行 超出 space 时清除来源存储时用作信号。我不会以任何方式依赖它。

相反,有一个名为“Persistent Storage”的网络平台功能,您可以使用它明确请求您的源存储不会因 space 限制而被清除。这是您可以更加确定地依赖的东西。来自那篇文章:

Beginning with Chrome 55, Chrome will automatically grant the persistence permission if any of the following are true:

  • The site is bookmarked (and the user has 5 or less bookmarks)
  • The site has high site engagement
  • The site has been added to home screen
  • The site has push notifications enabled

The permission is automatically denied in all other cases. The goal is to ensure that users can rely on their favorite web apps and not find they have suddenly been cleared.

你会像这样使用它:

if (navigator.storage && navigator.storage.persist) {
  navigator.storage.persist().then((granted) => {
    // Optionally update your UI based on the granted state.
  });
}