Giacomo Balli profile picture
Giacomo Balli
Innovation consultant specializing in mobile strategy
Let's Chat

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: Mon, 11 Jan 2016 02:47:24 +0000