Giacomo Balli profile picture
Giacomo Balli
The Mobile Guy

Over two decades of experience at your service.
I help business owners make better decisions.

Free 20-Minute Consultation LinkedIn

Check Storage Used

This code sample will allow you to check how much of your allowed storage quota you are using via localStorage (maximum depends on browser).

function checkStorageUsed() {
    var dim = thisDim = 0;
    for (var x in localStorage) {
        if (x.indexOf("com.apple.") == -1) {
            thisDim = (localStorage[x].length * 2) / 1024;
            console.log(x + ' :: ' + thisDim + 'kb');
            dim += thisDim;
        }
    }
    alert(dim.toFixed(2) + 'kb');
    return dim.toFixed(2);
}

Directions:
- Call checkStorageUsed(); and you will get a popup showing the result.

Note:
This snippet focuses on iOS development. Make sure to verify/adapt any vendor prefixes. Back to main listing.

Published: Sun, Jan 10 2016 @ 18:47:24
Back to Blog