Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML5 LocalStorage: How Much Space Do I Have Left?

Any idea how to check the remaining storage space in an HTML5 localstorage data store?

like image 526
Peder Rice Avatar asked Mar 04 '11 02:03

Peder Rice


People also ask

How do I check my local storage space?

Click the Application tab to open the Application panel. Expand the Local Storage menu. Click a domain to view its key-value pairs. Click a row of the table to view the value in the viewer below the table.

How much storage is localStorage?

It is limited to about 5MB and can contain only strings. LocalStorage is not accessible from web workers or service workers. Cookies have their uses, but should not be used for storage.

How do I know if my browser supports local storage?

localStorage browser support To be sure the browser supports localStorage , you can check using the following snippet: if (typeof(Storage) !== "undefined") { // Code for localStorage } else { // No web storage Support. }


2 Answers

I don't know if this helps, but you can check if it full.

“QUOTA_EXCEEDED_ERR” is the exception that will get thrown if you exceed your storage quota of 5 megabytes.

And this other answer might be related.

like image 146
Luis R. Avatar answered Sep 21 '22 13:09

Luis R.


Default localStorage allocated size is: 5Mb

 var allocated = 5;
    var total = 0;
    for(var x in localStorage){  
        var amount = (localStorage[x].length * 2) / 1024 / 1024;  
        total += amount;  
    }
    var remaining = allocated - total;
    console.log( "Used: " + total + " MB");
    console.log( "Remaining: " + remaining + " MB");
like image 42
sanman Avatar answered Sep 20 '22 13:09

sanman