Paulund
2019-03-16 #development

Local Storage vs Session Storage vs Cookie Storage

If you're like me you always need to lookup the difference between local storage, session storage and cookies.

This post is for those's that are always reaching for that comparison.

Local Storage

  • Stores data with no expiry date
  • Cleared only via JavaScript or clearing browser cache
  • Storage limit is the largest of the 3 as b ig as 5MB
  • Not supported by older browsers IE7 or lower
  • Works on same-origin policy. So, data stored will only be available on the same origin.

Session Storage

  • Stores data only for the duration of the session, when the user closes their browser the data is lost
  • Top-level browsing context, therefore it's unique to each browser tab
  • Storage limit is larger than cookies at 5MB
  • Not supported by older browsers IE7 or lower

Cookies

  • Stores data that can be transferred to the server via headers
  • LocalStorage and SessionStorage can only be accessed on client-side
  • Expiry is set on creation of the cookie
  • Storage limit is smallest at 4kb
  • Cookies can be made secure making client side unable to read the contents. This is important for authentication to store user tokens.