Calculating usage of localStorage space

You may be able to get an approximate idea by using the JSON methods to turn the whole localStorage object to a JSON string:

JSON.stringify(localStorage).length

I don’t know how byte-accurate it would be, especially with the few bytes of added markup if you’re using additional objects – but I figure it’s better than thinking you’re only pushing 28K and instead doing 280K (or vice-versa).

Leave a Comment