Cookie and localstorage - the second completely replaces the first one, or does it all depend on the situation? If it depends on the situation, then how to understand when to use one, and when another?

Colleagues, thank you for the comprehensive answer!

    2 answers 2

    Cookies are transmitted to the server with each request - so it makes sense to use them for something that is needed on the server. Let's say authorization, or, for example, view parameters, necessary when building a page on a server, such as a language.

    Everything else that is necessary only at the frontend level, as I understand it, is better to keep in Local Storage. There and will get more, and there will be no problems with overflow (if there are too many cookies, some servers may stop issuing any answer whatsoever).

    If absolutely all browsers like IE7 are needed, I would advise using a polyfill, so that in this case cookies are used only as a last resort.

      Cookies are very limited. In one cookie there can be only 4096 characters, and their number per domain is about 30-50, depending on the browser. In the local storage, we can store 5-10mb or more for a long time.

      The biggest difference between a cookie and localStorage is that the first one works with the server, and the second does not.

      Source: https://myrusakov.ru/html5-local-storage.html