Is there a way to increase the size of localStorage in Google Chrome to avoid QUOTA_EXCEEDED_ERR: DOM Exception 22

前端 未结 4 888
忘了有多久
忘了有多久 2020-12-08 19:46

I\'ve written a webapp that allows you to store the images in the localStorage until you hit save (so it works offline, if signal is poor).

When the localStorage rea

相关标签:
4条回答
  • 2020-12-08 20:22

    You can't but if you save JSON in your localStorage you can use a library to compress data like : https://github.com/k-yak/JJLC

    demo : http://k-yak.github.io/JJLC/

    0 讨论(0)
  • 2020-12-08 20:28

    The quota is for the user to set, how much space he wishes to allow to each website.

    Therefore since the purpose is to restrict the web pages, the web pages cannot change the restriction.

    If storage is low, you can prompt the user to increase local storage.

    To find out if storage is low, you could probe the local storage size by saving an object then deleting it.

    0 讨论(0)
  • 2020-12-08 20:35

    You can't, it's hard-wired at 5MB. This is a design decision by the Chrome developers.

    In Chrome, the Web SQL db and cache manifest also have low limits by default, but if you package the app for the Chrome App Store you can increase them.

    See also Managing HTML5 Offline Storage - Google Chrome.

    0 讨论(0)
  • 2020-12-08 20:43

    5MB is a hard limit and that is stupid. IndexedDB gives you ~50MB which is more reasonable. To make it easier to use try Dexie.js https://github.com/dfahlander/Dexie.js

    Update:

    Dexie.js was actually still an overkill for my simple key-value purposes so I wrote this much simpler script https://github.com/DVLP/localStorageDB

    with this you have 50MB and can get and set values like that

    // Setting values
    ldb.set('nameGoesHere', 'value goes here');
    
    // Getting values - callback is required because the data is being retrieved asynchronously:
    ldb.get('nameGoesHere', function (value) {
      console.log('And the value is', value);
    });
    

    Copy/paste the line below so ldb.set() and ldb.get() from the example above will become available.

    !function(){function e(t,o){return n?void(n.transaction("s").objectStore("s").get(t).onsuccess=function(e){var t=e.target.result&&e.target.result.v||null;o(t)}):void setTimeout(function(){e(t,o)},100)}var t=window.indexedDB||window.mozIndexedDB||window.webkitIndexedDB||window.msIndexedDB;if(!t)return void console.error("indexDB not supported");var n,o={k:"",v:""},r=t.open("d2",1);r.onsuccess=function(e){n=this.result},r.onerror=function(e){console.error("indexedDB request error"),console.log(e)},r.onupgradeneeded=function(e){n=null;var t=e.target.result.createObjectStore("s",{keyPath:"k"});t.transaction.oncomplete=function(e){n=e.target.db}},window.ldb={get:e,set:function(e,t){o.k=e,o.v=t,n.transaction("s","readwrite").objectStore("s").put(o)}}}();
    
    0 讨论(0)
提交回复
热议问题