Web Storage (or DOM storage) represents a mechanism for a better and more secured way of persisting data on the client than cookies. Web Storage is better in the following situations:
When you need greater storage capacity (it can keep 5 - 10 MB per the available storage, depending on the web browser)
When you don't need to communicate with the server to manage the client data
When you don't want the stored data to expire
When the stored data spans across different tabs or windows of the same browser
There are two Web Storage objects (Session
and Local
) that can be used to persist the user data in the web browser for the length of the session and indefinitely. Both of them have a similar simple API declared via the Storage interface. Web Storage has an event-driven implementation. The storage event is fired whenever a storage area changes.