I recently discovered that it's possible for the user to clear HTML5's localStorage
value, which caused me to wonder... exactly how persistant is localStorage
? If Flash crashes and wipes all my cookies, would I lose my localStorage data? What if my local cache was cleared to make way for a browser update?
I've seen this answer, but it doesn't address browser crashes, updates, cache clearing, etc. Is localStorage
really and truly permanent, as the aforementioned answer seems to mantain?
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.
The main features of localStorage are: Shared between all tabs and windows from the same origin. The data does not expire. It remains after the browser restart and even OS reboot.
Persistent storage is any data storage device that retains data after power to that device is shut off. It is also sometimes referred to as nonvolatile storage.
LocalStorage is not permanent. The storage belongs to the user so the user can clear it if they want to. Other web apps cannot mess with it, but the user is free to clear it or modify it if they want - it's their data, much like files that belong to a locally installed application are under the control of the computer user.
In addition, LocalStorage can be recycled when space is low.
You should think of LocalStorage as a long term cache that usually will remain with that particular browser on that particular computer, but will not always be there. Any truly persistent state must be stored on your own server.
Heck, if the user just decides to switch to another browser (much less a new computer), all Local Storage will appear to be empty in the new browser.
It most certainly isn't permanent. You shouldn't count on it.
Apart from situation where user is actively clearing the storage, his machine can be reinstalled. Or he can log from another computer. Your app better be able to handle that.
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