1

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?

1
  • It goes without saying that local storage is more permanent and that's its more general purpose. I'm curious about performance. Commented Apr 14, 2011 at 6:56

2 Answers 2

4

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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.

1 Comment

just a heads up that link (jsperf.com/localstorage-overhead) is now a dead link. I suspect because this is just old and the author/creator has moved on but wanted to call it out. Gives a 500: INTERNAL_SERVER_ERROR Code: FUNCTION_INVOCATION_FAILED ID: cle1::jb6pz-1657137430039-36c293748085

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.