The W3C spec for Web Storage (colloquially known as HTML5 local storage, although this is a misnomer) allows user agents to enforce a size limit, which is recommended at 5MB. According to various sources I've found around the net, a lot of modern browsers use this 5MB limit, except IE which gives 10MB.
First, I want to know, does the limit apply to the combined total of localStorage and sessionStorage, or to them individually?
Now, how do we actually cope with these limits? Is there any way to find out what the limit is for a particular browser? Is there any website which maintains statistics on the different browsers? Is an exception thrown when the browser goes over the limit? Is there a foolproof way to test for this exception "class" in different browsers?
AFAIK, there is no method in localStorage
object to determine its size. However, trying to write an amount of data that exceeds storage limit will result in an exception you can catch.
Take a look at http://arty.name/localstorage.html
Basically, you can wrap the writing function in a try...catch
block like this:
function write(value, name) {
try {
localStorage.field = value;
return true;
} catch (e) {
return false;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With