Search code examples
htmllocal-storagesession-storagesessionstorage

Is it possible to work out HTML5 utilisation of session/local storage?


Is it possible to work out utilisation of session storage?

Ideally to return current size of site session storage contents

http://www.w3schools.com/html/html5_webstorage.asp


Solution

  • I used this and it matched the local storage size here.

    function getLocalStorageSize() {
        var key, item, bytes = 0, keys = Object.keys(localStorage);
    
        for (var i = 0; i < keys.length; i++) {
            key = keys[i];
            item = localStorage[key];
            bytes += key.length + item.length;
        }
    
        return bytes;
    }