Be the first user to complete this post

  • 0
Add to List

sessionStorage vs localStorage vs cookie applications

sessionStorage, localStorage and cookie all are solutions to store data on client side. They can be used for

  • session management
  • user preference management
  • To setup never expiring tokens and many others.

sessionStorage - persists data only for a session

If your app redirects to a URL and comes back then its a new session. Hence, you can't use sessionStorage in that case.

localstorage - persists data until cleared explicitly, hence it persists across sessions

If you want your data to be cleared after sometime but still persist across different sessions, then its difficult to with localStorage.

cookie - persists until the cookie expires irrespective of session

You can use it across multiple sessions and you can delete it programmatically.



Also Read:

  1. Remove the blank value from a html select option dropdown
  2. window.onload vs document.onload
  3. A simple requestAnimationFrame example visually explained
  4. Getting started with localStorage vs sessionStorage in html5