我写了一个web应用程序,允许您将图像存储在localStorage中,直到您点击保存(因此,如果信号不好,它可以离线工作)。
当localStorage达到5MB时,Google Chrome会在JavaScript控制台日志中生成错误:
未捕获错误:QUOTA_EXCEEDED_ERR:DOM异常22
如何在Google Chrome上增加localStorage配额的大小?
我写了一个web应用程序,允许您将图像存储在localStorage中,直到您点击保存(因此,如果信号不好,它可以离线工作)。
当localStorage达到5MB时,Google Chrome会在JavaScript控制台日志中生成错误:
未捕获错误:QUOTA_EXCEEDED_ERR:DOM异常22
如何在Google Chrome上增加localStorage配额的大小?
7条答案
按热度按时间r6vfmomb1#
5 MB是一个硬限制,这是愚蠢的。IndexedDB给你~ 50 MB,这是更合理的。为了更容易使用,请尝试Dexie.js https://github.com/dfahlander/Dexie.js
更新:
实际上,Dexie.js对于我简单的键-值目的来说仍然是大材小用,所以我编写了这个简单得多的脚本https://github.com/DVLP/localStorageDB
这样你就有了50 MB的空间,可以获取和设置类似的值
复制/粘贴下面的行,以便上面示例中的
ldb.set()
和ldb.get()
可用。tjvv9vkg2#
你不能,它是硬连接在5MB。这是一个design decision by the Chrome developers。
在Chrome中,默认情况下Web SQL数据库和缓存清单也有较低的限制,但如果您为Chrome App Store打包应用程序,则可以增加它们。
Managing HTML5 Offline Storage - Google Chrome。
goucqfw63#
你不能,但是如果你把JSON保存在localStorage中,你可以使用一个库来压缩数据,比如:https://github.com/k-yak/JJLC
演示:http://k-yak.github.io/JJLC/
yi0zb3m44#
配额是由 * 用户 * 设置的,他希望允许每个网站有多少空间。
因此,由于目的是限制网页,所以网页不能改变限制。
如果存储空间不足,您可以提示用户增加本地存储空间。
要查明存储是否不足,可以通过保存对象然后删除它来探测本地存储大小。
9gm1akwq5#
在这里你可以测试你的程序,你应该也处理的情况下,当cuota超过
3b6akqbq6#
https://stackoverflow.com/a/5664344/2630686上面的答案是非常惊人的。我在我的项目中应用了它,并实现了一个完整的解决方案来请求各种资源。
jaql4c8m7#
我也遇到了同样的问题。经过仔细考虑,我认为从localStorage迁移到其他类型的本地存储,如indexedDB,是处理大量数据时更好的方法。
原因是localStorage对阻塞的同步进程进行操作。通常不建议使用同步进程存储大量数据(这可能是Chrome开发人员团队坚决不允许用户或开发人员增加localStorage的5MB硬限制的原因)。
不过,说实话...我们欣赏localStorageAPI的简单性、易用性和直接性。它在这些方面与indexedDB不同。
因此,我建议使用替代库:https://github.com/dreamsavior/Better-localStorage
此库的设计与localStorage类似,使迁移过程变得简单:
使用本机API,您需要执行以下操作: