最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Does HTML5 localStorage maximum size include key names? - Stack Overflow

programmeradmin2浏览0评论

HTML5's localStorage WebStorage has a maximum size of 5MB.

Does this include the key names?

For instance, if I were to use key names "quite-a-long-key-name-and-this-is-only-1" instead of "key1", would I run out of space sooner?

On a slightly related topic; is there any de-facto convention for naming localStorage keys? How are namespace collisions prevented when using third party JS scripts?

HTML5's localStorage WebStorage has a maximum size of 5MB.

Does this include the key names?

For instance, if I were to use key names "quite-a-long-key-name-and-this-is-only-1" instead of "key1", would I run out of space sooner?

On a slightly related topic; is there any de-facto convention for naming localStorage keys? How are namespace collisions prevented when using third party JS scripts?

Share Improve this question edited Apr 8, 2022 at 9:42 Audwin Oyong 2,5313 gold badges19 silver badges36 bronze badges asked Jul 4, 2012 at 18:15 MartijnMartijn 3,7543 gold badges40 silver badges66 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 10

Does this include the key names?

Yes those do, they bee part of data eg they identify data you store and later retrieve so that got to be saved as well.

How are namespace collisions prevented when using third party JS scripts?

That's a good question, I generally prefix localStorage with application name. Though a better approach would be to create a hash eg some algorithim that accepts a string like application name, etc and later when reading you use them again.

First note that this is implementation dependent as the norm doesn't give a limit. So you shouldn't rely on the size.

Secondly, yes, the limit in today's browsers includes the names : this is the size of the storage space ("disk space").

In order to avoid collisions, I use namespace (eg myplugin.mypart.myval). 5 MB is already big for a storage that can be deleted or not available any more at any time so I never thought about reducing the size of the keys...

发布评论

评论列表(0)

  1. 暂无评论