Are there any pros/cons (especially performance-wise) in using local storage to replace cookie functionality?

Technology CommunityCategory: AngularAre there any pros/cons (especially performance-wise) in using local storage to replace cookie functionality?
VietMX Staff asked 3 years ago

Cookies and local storage serve different purposes.

  • Cookies are primarily for reading server-side,
  • Local Storage can only be read by the client-side.

So the question is, in your app, who needs this data — the client or the server? If it’s your client (your JavaScript), then by all means switch to local storage. You’re wasting bandwidth by sending all the data in each HTTP header.

If it’s your server, local storage isn’t so useful because you’d have to forward the data along somehow (with Ajax or hidden form fields or something). This might be okay if the server only needs a small subset of the total data for each request.