Do I need to worry about managing the size of html5 localStorage, or will least recently used items be automatically removed?
Local Storage data will not get cleared even if you close the browser. Because it's stored on your browser cache in your machine. Local Storage data will only be cleared when you clear the browser cache using Control + Shift + Delete or Command + Shift + Delete (Mac).
LocalStorage has no expiration time, Data in the LocalStorage persist till the user manually delete it. This is the only difference between LocalStorage and SessionStorage.
When you try to store data in localStorage, the browser checks whether there's enough remaining space for the current domain. If yes: The data is stored, overwriting values if an identical key already exists.
localStorage is similar to sessionStorage , except that while localStorage data has no expiration time, sessionStorage data gets cleared when the page session ends — that is, when the page is closed.
localStorage
will not expire.
According to the currently published working draft, data should not expire. Specifically, I refer to the beginning of sections 4.2 and 4.3, where it says:
4.2 and 4.3:
User agents should expire data from the local storage areas only for security reasons or when requested to do so by the user. User agents should always avoid deleting data while a script that could access that data is running.Note that in 4.2, it goes on to describe that
sessionStorage
will be deleted when the browser has closed. But localStorage
should not expire because of time. In the editor's draft, it says sessionStorage
(only) may be deleted if the storage limit is encountered.
Of course, each storage space gets 5MiB (a fair bit for textual data), and there will be an exception thrown if you attempt to go over this limit. That makes handling the space requirements quite simple, as you can simply catch the exception and clear the data if need be.
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