Skip to content

Instantly share code, notes, and snippets.

@nandomoreirame
Forked from amitmerchant1990/console.js
Created August 29, 2025 15:46
Show Gist options
  • Save nandomoreirame/bd6bf502c8c6c26fb143383c5ffcf041 to your computer and use it in GitHub Desktop.
Save nandomoreirame/bd6bf502c8c6c26fb143383c5ffcf041 to your computer and use it in GitHub Desktop.
Calculate used localStorage size for a website
let totalSize = 0;
for (let key in localStorage) {
if (localStorage.hasOwnProperty(key)) {
let keySize = new Blob([key]).size; // Size of the key
let valueSize = new Blob([localStorage[key]]).size; // Size of the value
totalSize += keySize + valueSize;
}
}
console.log(`Total localStorage size: ${totalSize} bytes`);
console.log(`Total size in KB: ${(totalSize / 1024).toFixed(2)} KB`);
console.log(`Total size in MB: ${(totalSize / (1024 * 1024)).toFixed(2)} MB`);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment