由于localStorage
(当前)仅支持将字符串作为值,并且为了做到这一点,需要先将对象进行字符串化(存储为JSON-string),然后才可以定义值的长度。
有谁知道是否存在适用于所有浏览器的定义?
由于localStorage
(当前)仅支持将字符串作为值,并且为了做到这一点,需要先将对象进行字符串化(存储为JSON-string),然后才可以定义值的长度。
有谁知道是否存在适用于所有浏览器的定义?
因此,一旦我开发了Chrome(桌面浏览器)扩展程序并测试了本地存储的实际最大大小。
我的结果:
Ubuntu 18.04.1 LTS (64-bit)
Chrome 71.0.3578.98 (Official Build) (64-bit)
Local Storage content size 10240 KB (10 MB)
除了10240 KB
用法以外,还返回了以下错误:
未捕获的DOMException:无法在“存储”上执行“ setItem”:设置“便笺”的值超出了配额。
不要假设5MB可用-本地存储容量会因浏览器而异,其中2.5MB,5MB和无限制是最常见的值。来源:http://dev-test.nemikor.com/web-storage/support-test/
可以简单地将网络存储视为Cookie的一种改进,它提供了更大的存储容量(Google Chrome中每个原始站点10 MB(https://plus.google.com/u/0/+FrancoisBeaufort/posts/S5Q9HqDB8bh),Mozilla Firefox和Opera;在Internet Explorer中每个存储区10 MB)和更好的编程界面。
并且引用了John Resig的文章 [2007年1月发布]:
储存空间
It is implied that, with DOM Storage, you have considerably more storage space than the typical user agent limitations imposed upon Cookies. However, the amount that is provided is not defined in the specification, nor is it meaningfully broadcast by the user agent.
If you look at the Mozilla source code we can see that 5120KB is the default storage size for an entire domain. This gives you considerably more space to work with than a typical 2KB cookie.
However, the size of this storage area can be customized by the user (so a 5MB storage area is not guaranteed, nor is it implied) and the user agent (Opera, for example, may only provide 3MB - but only time will tell.)
实际上,Opera没有5MB的限制。随着应用程序需求的增加,它提供了增加限制的功能。用户甚至可以为域选择“无限存储”。
您可以轻松地自己测试localStorage限制/配额。
Browser | Chrome | Android Browser | Firefox | iOS Safari
Version | 40 | 4.3 | 34 | 6-8
Available | 10MB | 2MB | 10MB | 5MB
Browser | Chrome | Opera | Firefox | Safari | IE
Version | 40 | 27 | 34 | 6-8 | 9-11
Available | 10MB | 10MB | 10MB | 5MB | 10MB
我正在执行以下操作: