sessionStorage vs localStorage vs cookie applications

ses­sion­Stor­age, local­Stor­age and cookie all are solu­tions to store data on client side. They can be used for

  • ses­sion management
  • user pref­er­ence management
  • To setup never expir­ing tokens and many others.

ses­sion­Stor­age — per­sists data only for a session

If your app redi­rects to a URL and comes back then its a new ses­sion. Hence, you can’t use ses­sion­Stor­age in that case.


local­stor­age — per­sists data until cleared explic­itly, hence it per­sists across sessions

If you want your data to be cleared after some­time but still per­sist across dif­fer­ent ses­sions, then its dif­fi­cult to with localStorage.


cookie — per­sists until the cookie expires irre­spec­tive of session

You can use it across mul­ti­ple ses­sions and you can delete it programmatically.


You may also like...