服务工作者的存储限制是多少? [英] What is the storage limit for a service worker?

查看:130
本文介绍了服务工作者的存储限制是多少?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大多数浏览器为localStorage提供每个域5MB的存储限制。
服务工作者是否有这样的内存限制/限制?

Most of the browsers provide localStorage with the storage limit of 5MB per domain. Are there such memory limits/constraints with respect to service workers?

我知道网络工作者(服务工作者所基于的)没有这样的限制。但Web Workers并不完全用于资产缓存,而是更多地用于处理(因此CPU是主要关注点)。

I know that web workers (on which service workers are based) don't have such limitations. But Web Workers are not exactly used for assets caching, instead they're used more for processing (so CPU is the main concern there).

如果没有限制内存大小,设计糟糕的网站可能会崩溃吗?

If there's no limit on the memory size, could a badly designed website crash the browser?

推荐答案

更新2018年1月15日

StorageManager Storage API接口正在成为所有与存储相关的api查询的标准。正如 @ miguel-lattuada 所述,估计API 将提供对可用存储使用Web应用程序的存储的估计。此外,请注意 QuotaExceededError 异常,这将有所帮助我们处理错误情景。

The StorageManager interface of Storage API is becoming a standard for all storage related api queries. As mentioned by @miguel-lattuada, the estimate API would provide an estimate of the storage used a web app the available storage. Also, note the QuotaExceededError exception which would help us in handling error scenarios.

例如代码:

if ('storage' in navigator && 'estimate' in navigator.storage) {
  navigator.storage.estimate().then(({usage, quota}) => {
    console.log(`Using ${usage} out of ${quota} bytes.`);
  }).catch(error => {
    console.error('Loading storage estimate failed:');
    console.log(error.stack);
  });
} else {
  console.error('navigator.storage.estimate API unavailable.');
}

有关详细信息,请参阅以下2篇精彩文章:

For more info, refer the following 2 great articles:

  • MDN Web docs - Storage API
  • Google Developers: Estimating Available Storage Space

2017年3月16日(仅供参考/历史记录)

最近我看到了这篇文章: offline-cookbook 如下所示:

Recently I came across this article: offline-cookbook which states as below:

您的来源有一定的可用空间,可以按照自己的意愿行事。 可用空间在所有原始存储:LocalStorage,IndexedDB,F​​ilesystem,当然还有Caches之间共享。

Your origin is given a certain amount of free space to do what it wants with. That free space is shared between all origin storage: LocalStorage, IndexedDB, Filesystem, and of course Caches.

您获得的金额未指定,它将根据设备和存储条件而有所不同。你可以通过以下方式了解你有多少:

The amount you get isn't spec'd, it will differ depending on device and storage conditions. You can find out how much you've got via:

navigator.storageQuota.queryInfo("temporary").then(function(info) {
   console.log(info.quota);
   // Result: <quota in bytes>
   console.log(info.usage);
   // Result: <used data in bytes>
});

以上代码可能无法在所有浏览器中使用。 (例如:在chrome< 48中可能需要查找webkitPersistentStorage等)

The above code might not work in all the browsers. (for eg: in chrome<48 one might have to look for webkitPersistentStorage etc)

其他有用的信息/资源


  1. 根据 Addy Osmani的离线存储for Progressive Web Apps

Chrome和Opera :您的存储是按来源(而不是每个API)。两种存储机制都将存储数据,直到达到浏览器配额。应用可以使用配额管理API检查他们使用的配额(如上所述)。

In Chrome and Opera: Your storage is per origin (rather than per API). Both storage mechanisms will store data until the browser quota is reached. Apps can check how much quota they’re using with the Quota Management API (as described above).

Firefox 没有限制,但会在存储50MB数据后提示

Firefox no limits, but will prompt after 50MB data stored

移动Safari 最大50MB

Desktop Safari 无限制(5MB后提示)

Desktop Safari unlimited (prompts after 5MB)

IE10 + 最大值为250MB,提示为10MB

IE10+ maxes at 250MB and prompts at 10MB

关于使用的详细指南移动浏览器的配额由Eiji Kitamura提供。

A more detailed guide on Working with quota on mobile browsers by Eiji Kitamura.

目前这些是最相关的文章/解决方案对于我的问题。如果有人知道更好的文章或规格,请分享。

For now these are the most relevant articles/solutions found for my problem. If anyone knows some better article or specifications please share.

这篇关于服务工作者的存储限制是多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆