This browser API provides mechanisms that can store pairs of keys and values and is more intuitive than using Cookies.
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.
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.
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.
Both are vulnerable to XSS attacks, so Local Storage and Session Storage are good places to store public and non-sensitive data.