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.