I want to reduce the loading times on my websites by moving all cookies to local storage since they seem to have the same functionality List the pros and cons of using local storage for cookie functionality except for obvious compatibility issues?

Best Answer


Cookies and local storage serve different purposes Cookies are primarily for reading server-side , local storage can only be read by the client-side . Why does a client or a server need this data?

If your client is javascript then you should switch You're wasting bandwidth by sending all the data to each http header

Local storage is not really useful if it's your server because you have to get it in the way of ajax or hidden fields or something This might be okay if the server only needs a small subset of the total data for each request

You'll want to leave your session cookie as a cookie either way though.

As per the technical difference, and also my understanding.

  1. Apart from being an old way of saving data, Cookies give you a limit of 4096 bytes (4095, actually) — it's per cookie. Local Storage is as big as 5MB per domainSO Question also mentions it.

  2. localStorage is an implementation of the Storage Interface. It stores data with no expiration date , and gets cleared only through JavaScript, or clearing the Browser Cache / Locally Stored Data — unlike cookie expiry.