Skip to content

Latest commit

 

History

History
49 lines (26 loc) · 1.72 KB

README.md

File metadata and controls

49 lines (26 loc) · 1.72 KB

Web Storage API

This browser API provides mechanisms that can store pairs of keys and values and is more intuitive than using Cookies.


Local Storage

Maintains a separate storage area for each origin.

It will persist data even if you close the page (tab) or browser.

This persisted data has no expiration date, which means that the stored data only can be cleared through JavaScript, clearing the browser cache or clearing directly at the Application tab inside the DevTools.

Has a limit of data size up to 5mb.


Session Storage

Maintains a separate storage area for each origin.

It will be available for the duration of the page session (including page reloads).

It means that the stored data is only available until the page (tab) or browser is closed.

Has a limit of data size up to 5mb.


Usage

Both are available via Window.localStorage and Window.sessionStorage properties.

To be more precise, in supporting browsers the Window object implements the WindowLocalStorage and WindowSessionStorage objects, which are the localStorage and sessionStorage properties. Invoking one of these will create an instance of the Storage object, through which data items can be set, retrieved and removed.


What can I store inside Local Storage and Session Storage?

Both are vulnerable to XSS attacks, so Local Storage and Session Storage are good places to store public and non-sensitive data.


References