开发者

HTML5 localStorage vs sesionStorage vs another typeof data storage performance

I need to fetch some chunks of data in a Javascript loop. The pieces will probably be small between 2 and 20 Kb but being in a loop I need speed. I can get these pieces of code from local storage:

var code = localStorage.getItem(myVar);

or even from jQuery .data()

var code = $('#myDiv').data(myVar);

I was unable to find info on localStorage or sesionStorage开发者_JS百科 speed or if I can cache these values into memory.

What would be fastest and better to use? Thanx


http://www.html5rocks.com/tutorials/speed/quick/#toc-databases

As a rule of thumb: The more data you have, the more appropriate the client-side databases become. To find the break-even point, you'll have do do some testing i suppose.


Webstorage is perfect for chunks of data with that dimension and it' really fast retrieving data from the browser. You don't need any cache, because the data are on the browser, you can rather use those data with offline applications as well.

I would suggest using pure JS, as it doesn't add any overhead or any dependencies and the WebStorage API are quite straightforward.

If you wanna know more about WebStorage, try to read my article

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜