Skip to content

Instantly share code, notes, and snippets.

@larchanka
Last active January 24, 2025 14:23
Show Gist options
  • Save larchanka/602eb5b3921de92369b9b3caffceafc2 to your computer and use it in GitHub Desktop.
Save larchanka/602eb5b3921de92369b9b3caffceafc2 to your computer and use it in GitHub Desktop.
JavaScript function to calculate the total size of all data stored in browser's local storage
/**
* Calculates the total size of all the items in local storage.
* @returns {Number} The total size of all the items in local storage in bytes.
*/
function calculateLocalStorageSize() {
return new Blob(Object.keys(localStorage).map(k => k + localStorage[k])).size;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment