Features of LocalStorage
- LocalStorage is used to store the information of the user persistently in the browser.
- It does not get cleared unless JavaScript code running on that website deletes it or we erase it using browser settings.
- Data stored in local storage is not sent for the server upon every request.
- Data is not lost even if we close the browser, or restart the computer.
- Data is stored in the form of key- value pairs.
- The web pages from the same origin in the other tabs/windows can also use this local storage data.
- Depending upon the browser, storage limit for a origin(domain + port + protocol) will be up to 10 MB.
Example: We visited a site in Tab 1 and the same site in Tab 2 or another window. We stored some data from each tab or window; they are centrally stored at the same place (unlike for sessionstorage, where each tab has its own storage even though the origin is the same) and can be accessed from all the web pages originating from the same origin in the same tab.
How to save data in session and local storage ?
SessionStorage and LocalStorage are the two most important ways to store data in the browser. SessionStorage is the temporary storage that web applications use to store data, whereas LocalStorage is the persistent storage that websites use to manage our data. These storages reside in the browser’s memory.
Apart from these storage browser also stores information in Cookies. A Cookie is just some textual information about website. Cookies help to make the browsing experience better. Cookies are website specific and hold the information of frequently visited websites
Table of Content
- Steps to open Session Storage and Local Storage
- Memory Capacity
- Features of Session Storage
- When to use Session Storage?
- Methods of Session Storage object
- Demonstrating Session Storage
- Features of Local Storage
- When to use LocalStorage?
- Methods of Local Storage object
- Demonstrating Local Storage Object