Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do I need to worry about managing the size of html5 localStorage, or will least recently used items be automatically removed?

Do I need to worry about managing the size of html5 localStorage, or will least recently used items be automatically removed?

like image 408
Kyle Avatar asked Mar 23 '11 20:03

Kyle


People also ask

Does clearing history clear local storage?

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).

Does local storage ever expire?

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.

What happens if local storage is full?

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.

How long does data stay in local storage?

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.


1 Answers

The short answer

localStorage will not expire.

The long answer

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.

like image 139
Reid Avatar answered Nov 01 '22 01:11

Reid