Matrym
Matrym

Reputation: 17053

HTML5 Local Storage vs JSON Object

Are there performance benefits to storing in Local Storage over a JSON object in js? I would assume that it takes (slightly) longer to access, but bogs down the browser (slightly) less.

Any thoughts?

Upvotes: 1

Views: 1987

Answers (2)

Rajat
Rajat

Reputation: 34128

There is a test case at jsPerf which comes close: http://jsperf.com/localstorage-overhead

As far as I am concerned, I wouldn't bother moving my JS object to localStorage to free up memory. This seems like a overkill to me. Ideally, most of the stuff should be scoped inside functions and there should be as little stuff as possible in the global namespace(something that will live in memory for your app's entire lifetime).

Hope this helps.

Upvotes: 1

Alexandr
Alexandr

Reputation: 9505

Storing in JSON object - is in memory. As soon as you close page/browser it is gone. Local storage - is a persistent storage. You may save you JSON object as stringified in it. And if you close your browser you may then get it back.

Upvotes: 4

Related Questions