I need a way to find the total size taken by an application using HTML5 sessionStorage
/ localStorage
at run time.
I don't want profiler-based approaches.
What I'm currently doing is -
var data = 0;
for(var v in window.sessionStorage){
data += window.sessionStorage.getItem(v);
}
console.log(data);//.length to get char length
And then I copy-paste this value into a text-file and check the size.
Ugly and still doesn't help me either. Is there a way (any method) in the HTML5 API's that have this in-built?
Thank you.
No, not cross browser. IE sort of has it, the others don't. But of course, remaining size left on the domain can be calculated. See below examples.
For IE only:
var remSpace = window.localStorage.remainingSpace;
For FF/Chrome/Safari:
var limit = 1024 * 1024 * 5; // 5 MB
var remSpace = limit - unescape(encodeURIComponent(JSON.stringify(localStorage))).length;
Opera: 5 MB is standard but the browser offers to increase limit as applications require more space.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With