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, bu开发者_如何学Got bogs down the browser (slightly) less.
Any thoughts?
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.
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.
精彩评论