SessionStorage, localStorage and Cookies

All these three topics or storage are used to store data on the client side which means basically web browsers like Chrome or any others. Each one has their own storage and their expiration limit.

All storage and cookie can be viewed on console application tab. You can view your data on your respective url.

localStorage can be viewed simply as an improvement on cookies with much greater storage capacity. LocalStorage available size is 5mb comparatively more space to work with than a typical 4KB cookie. It stores data with no expiration date. It will get clear when we clear our browser cache / Locally stored data or will get clear only through Javascript.

An example to store data in localStorage using jQuery :

SessionStorage is similar to localStorage. SessionStorage object stores data only for a session which mean it will expires when the browser is closed. Storage limit is larger than a cookie (at least 5MB).

An example to store data in SessionStorage using jQuery :

Cookies has 4KB limit for the entire cookie, including name, value, expiry date etc. We can set expiry time for each cookie.

An example to store data in Cookies using jQuery :

Well, you can check your browser support :

 

Sharing is caring!

Related Post