Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

localStorage data persistence

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?

like image 955
Elliot Bonneville Avatar asked Mar 15 '12 22:03

Elliot Bonneville


People also ask

How long does local storage data last?

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.

Does localStorage persist after refresh?

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.

What is persistent data store?

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.


2 Answers

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.

like image 196
jfriend00 Avatar answered Oct 13 '22 00:10

jfriend00


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.

like image 33
Sergio Tulentsev Avatar answered Oct 13 '22 01:10

Sergio Tulentsev