Calculating usage of localStorage space

后端 未结 12 1587
悲哀的现实
悲哀的现实 2020-11-27 10:28

I am creating an app using the Bespin editor and HTML5\'s localStorage. It stores all files locally and helps with grammar, uses JSLint and some other parsers for CSS and HT

12条回答
  •  孤街浪徒
    2020-11-27 10:45

    You may be able to get an approximate idea by using the JSON methods to turn the whole localStorage object to a JSON string:

    JSON.stringify(localStorage).length
    

    I don't know how byte-accurate it would be, especially with the few bytes of added markup if you're using additional objects - but I figure it's better than thinking you're only pushing 28K and instead doing 280K (or vice-versa).

提交回复
热议问题