Giacomo Balli profile picture
Giacomo Balli
The Mobile Guy

For founders and teams whose growth depends on mobile.
Clear judgment when AI, vendors, and product choices muddy the roadmap.

Find the Right Move 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