Local Storage vs Cookies

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 client (like JavaScript), then we can store all data in local storage.

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.

    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.


    If our client app using REST API, then using cookie to store and transmit session id is not good idea in REST.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s