Languages
[Edit]
EN

HTML5 - localStorage vs sessionStorage

0 points
Created by:
Dragontry
731

In this article, we would like to show you the difference between localStorage and sessionStorage in HTML5.

Quick solution:

The difference between localStorage and sessionStorage is the data storage time. While data in localStorage doesn't expire (it can only be explicitly deleted), data in sessionStorage is cleared when the web browser session ends for the page (do not confuse it with server sessions).

1. Overview

Edit

The localStorage and sessionStorage both extend Storage that can store key/value (property/value) pairs and has built-in methods (like .length, .key( ), etc.).

2. localStorate

Edit

The localStorage stores data permanently. Once saved data is already there and the application can refer to it at any time, regardless of the session, unless the user manually deletes the contents of localStorage. There is also no built-in mechanism that would say how long data can be stored in localStorage (as e.g. in the case of cookies).

3. sessionStorate

Edit

The sessionStorage only works for the duration of the session. After the session ends, its storage is deleted.

 

References

Edit
  1. Storage - Web APIs | MDN
  2. Window.sessionStorage - Web APIs | MDN
  3. Window.localStorage - Web APIs | MDN

Alternative titles

  1. HTML5 - difference between localStorage and sessionStorage
  2. HTML5 - localStorage and sessionStorage differences
  3. HTML5 - local storage vs session storage
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join