Skip to content

Instantly share code, notes, and snippets.

@steffensbola
Created May 28, 2025 13:42
Show Gist options
  • Select an option

  • Save steffensbola/4319238a1357a513c8e00c8f0700fd86 to your computer and use it in GitHub Desktop.

Select an option

Save steffensbola/4319238a1357a513c8e00c8f0700fd86 to your computer and use it in GitHub Desktop.
Get the size of each entry in the Browser Local Storage
/* Gets the size of each entry in the Browser Local Storage. Original: https://stackoverflow.com/questions/4391575/how-to-find-the-size-of-localstorage*/
var _lsTotal=0,_xLen,_x;for(_x in localStorage){ if(!localStorage.hasOwnProperty(_x)){continue;} _xLen= ((localStorage[_x].length + _x.length)* 2);_lsTotal+=_xLen; console.log(_x.substr(0,50)+" = "+ (_xLen/1024).toFixed(2)+" KB")};console.log("Total = " + (_lsTotal / 1024).toFixed(2) + " KB");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment