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).
我编写了一个webapp,允许您将图像存储在localStorage中,直到您点击保存(因此它可以脱机工作,如果信号很差)。
When the localStorage reaches 5MB Google Chrome produces an error in the javascript console log:
当localStorage达到5MB时,Google Chrome会在javascript控制台日志中产生错误:
Uncaught Error: QUOTA_EXCEEDED_ERR: DOM Exception 22
未捕获错误:QUOTA_EXCEEDED_ERR:DOM异常22
How do I increase the size of the localStorage quota on Google Chrome?
如何在Google Chrome上增加localStorage配额的大小?
4 个解决方案
#1
11
You can't, it's hard-wired at 5MB. This is a design decision by the Chrome developers.
你不能,它的硬连线为5MB。这是Chrome开发人员的设计决策。
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.
在Chrome中,默认情况下,Web SQL数据库和缓存清单也有较低的限制,但如果您打包Chrome App Store的应用程序,则可以增加它们。
See also Managing HTML5 Offline Storage - Google Chrome.
另请参阅管理HTML5离线存储 - Google Chrome。
#2
4
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.
要确定存储是否较低,可以通过保存对象然后将其删除来探测本地存储大小。
#3
4
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
5MB是一个硬限制,这是愚蠢的。 IndexedDB为您提供~50MB更合理。为了更容易使用,请尝试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
Dexie.js实际上对我的简单键值目的来说仍然是一种矫枉过正,所以我编写了这个更简单的脚本https://github.com/DVLP/localStorageDB
with this you have 50MB and can get and set values like that
有这个你有50MB,可以得到和设置这样的值
// 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.
复制/粘贴下面的行,以便上面的示例中的ldb.set()和ldb.get()可用。
!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)}}}();
#4
1
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
你不能不,但如果你在localStorage中保存JSON,你可以使用库压缩数据,如:https://github.com/k-yak/JJLC
demo : http://k-yak.github.io/JJLC/
演示:http://k-yak.github.io/JJLC/
#1
11
You can't, it's hard-wired at 5MB. This is a design decision by the Chrome developers.
你不能,它的硬连线为5MB。这是Chrome开发人员的设计决策。
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.
在Chrome中,默认情况下,Web SQL数据库和缓存清单也有较低的限制,但如果您打包Chrome App Store的应用程序,则可以增加它们。
See also Managing HTML5 Offline Storage - Google Chrome.
另请参阅管理HTML5离线存储 - Google Chrome。
#2
4
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.
要确定存储是否较低,可以通过保存对象然后将其删除来探测本地存储大小。
#3
4
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
5MB是一个硬限制,这是愚蠢的。 IndexedDB为您提供~50MB更合理。为了更容易使用,请尝试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
Dexie.js实际上对我的简单键值目的来说仍然是一种矫枉过正,所以我编写了这个更简单的脚本https://github.com/DVLP/localStorageDB
with this you have 50MB and can get and set values like that
有这个你有50MB,可以得到和设置这样的值
// 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.
复制/粘贴下面的行,以便上面的示例中的ldb.set()和ldb.get()可用。
!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)}}}();
#4
1
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
你不能不,但如果你在localStorage中保存JSON,你可以使用库压缩数据,如:https://github.com/k-yak/JJLC
demo : http://k-yak.github.io/JJLC/
演示:http://k-yak.github.io/JJLC/