Skip to content
Advertisement

Does HTML5 localStorage maximum size include key names?

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?

Advertisement

Answer

Does this include the key names?

Yes those do, they become 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.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement