Storing data with cookies

Cookies are little strings, which, once set for a domain and path, are sent over and over to the server for every request. This is perfect for authentication, but not so good if you're using them to store some data that you need only once or that you need to access only on the frontend, such as a player's score in a game whose results you are not storing on the server.

People usually use cookies to store heavy data to make it available on some other path on the domain. This is a bad practice because you're transferring that data to the server all the time, and, if that data is heavy, it'll make your communication slow.

Get Learn ECMAScript - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.