The strategy of localStorage's storage space in FireFox and Chrome.

This artical will introduce the strategy of the usage of storage space of FireFox and Chrome.


recently our QA met an exception in production in Firefox, while this exception don't occur in chrome, the exception is as follows: 
“Persistent Storage maximum size reached” code:"1014" nsresult: "0x80530f6(NS_ERROR_DOM_QUOTA_REACHED); 

I checked the size of the localstorage on her machine, by using JSON.stringify(localStorage).length
The size is about 500KB, the size of the new item to set is about 300KB, the total size will be about 800KB, it is far less than 5MB, it is strange that localStorage has reached its maximum size. 

for example, suppose we have three different sub-domains under one top level domain "domain.com
do prepare: 
clear localstorage of a1.domain.com, a2.domain.com and a3.domain.com

in a1.domain.com run: 
localStorage.setItem(‘item1’,content1) // size of content1 is 2.3MB. 

in a2.domain.com run: 
localStorage.setItem(‘item2’,content2) // size of content2 is 2.7MB 

in a1.domain.com, run: 
JSON.stringify(localStorage).length; // 2.3MB 
localStorage.getItem(‘item1’); // content1 
localStorage.getItem(‘item2’); // undefined 

in a2.domain.com, run: 
JSON.stringify(localStorage).length; // 2.7MB 
localStorage.getItem(‘item1’); // undefined 
localStorage.getItem(‘item2’); // content2 

in a3.domain.com, run: 
JSON.stringify(localStorage).length; // 0KB 
localStorage.getItem(‘item1’); // undefined 
localStorage.getItem(‘item2’); // undefined 
localStorage.setItem(‘item3’,content3) // size of content3 is 100KB. 
result : Persistent Storage maximum size reached" code:"1014" nsresult: "0x80530f6(NS_ERROR_DOM_QUOTA_REACHED).

 

After research, I found that firefox shared the same space for localStorage per top level domain, that is a1.domain.com, a2.domain.com and a3.domain.com will share the same space of localStorage, because the top level domain of them are both “domain.com”

 

After doing the same test in chrome, I have following Conclusion:

in FireFox, all sub domains under the same top level domain don't share the data they stored in localStorage, but the total size of all the sub domains and the top level domain will be 5M.

in Chrome, each of the sub domains and the top level domain don't share the data they store in localStorage, and the total size of each sub-domain and top level domain will be 2.5M

转载于:https://www.cnblogs.com/zhongmi/p/3179285.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值