Local Storage, Session Storage

Local Storage, Session Storage

In this article, we will discuss local storage and session storage.

start

Developers often use Web Storage API to store some data into the web browser. Web storage objects localStorage and sessionStorage allow to save key/value pairs in the browser.

Advantages of Local Storage and Session Storage over Cookies

  • They are not sent to the server like cookies on every request.

  • Storage is bound to the origin.

  • Limit of storage is 5MB, it depends on the browser.

Local Storage

Data stored in local storage is shared between all tabs and windows from the same origin. The data do not get lost even after browser restart or reboot.

code-snapshot.png

Output:

Screenshot from 2021-06-11 10-19-50.png

Session Storage

This exists only within the current browser tab. Data in session storage is cleared when the page session ends.

code-snapshot.png

Output:

Screenshot from 2021-06-11 10-19-50.png

That's it for this article.