To reduce load times on our websites, we always cache some item in cookies and local storage. In this article some of differences between “Local Storage vs Cookies” is described.
Both Cookies and local storage serve difference purposes.
Choosing from these two
Cookies are primarily for reading server-side, local storage can only be read client-side.
So choosing from these two location to store data for our app, one question comes that, who needs this data : the client or the server?
If it’s our server need data, local storage isn’t so useful because we have to forward the data with each request by somehow (with Ajax or hidden form fields or something).
LocalStorage stays on the client, while cookies are sent with the HTTP header.
As per the technical difference:
- Apart from being an old way of saving data, Cookies give you a limit of 4096 bytes (4095, actually) – its per cookie. Local Storage is as big as 5MB per domain.
If our client app using REST API, then using cookie to store and transmit session id is not good idea in REST.Advertisements