localStorage值的最大大小是多少? [英] What is the max size of localStorage values?

查看:2423
本文介绍了localStorage值的最大大小是多少?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于 localStorage (当前)仅支持字符串作为值,为此,对象需要被字符串化(存储为JSON字符串),然后才可以存储,有关值的长度的定义限制。



有谁知道是否有一个定义适用于所有浏览器?

解决方案

引用 Wikipedia上的文章存储


可以简单地查看网络存储,作为对cookie的改进,提供更大的存储容量( 10谷歌浏览器每个来源的MB( https://plus.google.com/u / 0 / + FrancoisBeaufort / posts / S5Q9HqDB8bh ),Mozilla Firefox和Opera; Internet Explorer中每个存储区10 MB)以及更好的编程接口。

此外还引用 John Resig的文章 [2007年1月发布]:


存储空间



这意味着,使用DOM存储
,您的存储空间将比典型的用户代理
限制强加给Cookies的存储空间更大。
但是,
提供的金额未在规范中定义,
也不是由
用户代理有意义地广播。



如果查看Mozilla源代码
,我们可以看到5120KB是整个域的默认
存储大小。
与典型的2KB
cookie相比,这为你提供了更多的空间



但是,大小这个存储区域
可以由用户自定义(所以不能保证
5MB存储空间,
也不暗示)和用户代理
(Opera ,例如,可能只提供
3MB - 但只有时间才能说明。)



Since localStorage (currently) only supports strings as values, and in order to do that the objects need to be stringified (stored as JSON-string) before they can be stored, is there a defined limitation regarding the length of the values.

Does anyone know if there is a definition which applies to all browsers?

解决方案

Quoting from the Wikipedia article on Web Storage:

Web storage can be viewed simplistically as an improvement on cookies, providing much greater storage capacity (10 MB per origin in Google Chrome(https://plus.google.com/u/0/+FrancoisBeaufort/posts/S5Q9HqDB8bh), Mozilla Firefox, and Opera; 10 MB per storage area in Internet Explorer) and better programmatic interfaces.

And also quoting from a John Resig article [posted January 2007]:

Storage Space

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.)

这篇关于localStorage值的最大大小是多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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