最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - localStorage store large size data - Stack Overflow

programmeradmin1浏览0评论

I want to use localStorage to store large amount of data(like 800GB), according to /localstorage.html and also I'm using Firefox, I changed my localStorage size and also the cache size. So the size isn't a problem. However, I write some jquery like the following:

 $("a[href]").each(function(){
    $(this).click(function(event){
       localStorage.test += "somenewinformation";
      ...

If this localStorage.test already have large amount of data like 400GB, so the storing information step would be extremely slow. When I click on a link,will the jquery wait for me to finish the appending new information to localStorage.test or it will just go to the next page and information in localStorage.test will all lost or localStorage.test will just remain the old value? What I dont understand is whether a new thread will be generated to do this storing in background or not and closing browser in the middle will affect it or not.

Sorry about the messy description and thanks in advance!

I want to use localStorage to store large amount of data(like 800GB), according to http://arty.name/localstorage.html and also I'm using Firefox, I changed my localStorage size and also the cache size. So the size isn't a problem. However, I write some jquery like the following:

 $("a[href]").each(function(){
    $(this).click(function(event){
       localStorage.test += "somenewinformation";
      ...

If this localStorage.test already have large amount of data like 400GB, so the storing information step would be extremely slow. When I click on a link,will the jquery wait for me to finish the appending new information to localStorage.test or it will just go to the next page and information in localStorage.test will all lost or localStorage.test will just remain the old value? What I dont understand is whether a new thread will be generated to do this storing in background or not and closing browser in the middle will affect it or not.

Sorry about the messy description and thanks in advance!

Share Improve this question asked Jun 22, 2013 at 22:11 user2489547user2489547 1811 gold badge1 silver badge9 bronze badges 18
  • 3 You know, there's a reason localStorage is limited. – lonesomeday Commented Jun 22, 2013 at 22:18
  • 3 There are tasks for which Javascript is suited. Then there is this task. Seriously, use server-side code and a proper database.. – lonesomeday Commented Jun 22, 2013 at 22:43
  • 15 My harddrive cannot even store 800GB. – TimWolla Commented Jun 22, 2013 at 22:43
  • 1 @ TimWolla This is done on a computer with harddrive 1TB so the size is not a problem. – user2489547 Commented Jun 22, 2013 at 22:47
  • 3 Seriously, relying on Javascript localStorage for this amount of data is nuts - it's not designed for it. I'd say using Javascript for this is nuts too, but if you're committed to a javascript approach look at the FileSystem API. At least that way you can use a proper filesystem to split the data up. – user1864610 Commented Jun 23, 2013 at 4:11
 |  Show 13 more comments

2 Answers 2

Reset to default 18

You can't! The usual limit is 5 MB.

Some browsers such as Opera allow you to adjust the size, but this is purely dependent on the browser and is a user-initiated action, not a programmable one.

And even if you could remember that localStorage can only store strings, so anything else need to be stringified first. That together with this being an key-value storage array you will run into pretty poor performance at the end.

If you need large storage capacity, look into File API instead. This is made to work with large files (Blobs) and you can store anything as a Blob.

800 Gb is a large size and File API can only work as fast as the file system (at best, more likely a bit slower as it is sandboxed, ie. not a pure file system).

More about File System API (Note: discontinued as of 4/2014):
http://www.w3.org/TR/file-system-api/

Tutorial:
http://www.html5rocks.com/en/tutorials/file/dndfiles/

Blob:
https://developer.mozilla.org/en-US/docs/Web/API/Blob

Update As the Filesystem API has been discontinued there are essentially only two options left (besides from storing data to the server):

  • Indexed Database API aka Indexed DB (recommended)
  • Web SQL (deprecated but still supported in browsers such as Safari)

Also these are initially limited in size by the browser. It is possible to request a larger quote which the user is asked to accept.

See more details about this API here:
http://www.w3.org/TR/IndexedDB/

There is LargeLocalStorage which provides a cross-browser way to storage large amounts of data locally. You can store binary data or strings.

LargeLocalStorage uses the FilesystemAPI on Chrome, IndexedDB in IE and Firefox and WebSQL in Safari.

发布评论

评论列表(0)

  1. 暂无评论