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

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

问题描述

由于 localStorage(当前)仅支持字符串作为值,并且为了做到这一点,对象需要在存储之前进行字符串化(存储为 JSON 字符串),是否有定义的关于值长度的限制.

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?

推荐答案

引用自 维基百科关于 Web 存储的文章:

网络存储可以简单地视为对 cookie 的改进,提供更大的存储容量(Google Chrome 中每个来源 10 MB(https://plus.google.com/u/0/+FrancoisBeaufort/posts/S5Q9HqDB8bh)、Mozilla Firefox 和 Opera;每个存储 10 MBInternet Explorer 中的区域)和更好的编程界面.

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.

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

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

存储空间

这暗示,使用 DOM Storage,你有更多的存储空间空间比典型的用户代理对 Cookie 施加的限制.但是,提供的金额规范中没有定义,也不是有意义的广播用户代理.

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.

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

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.

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

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天全站免登陆