Cookie vs Local Storage
A cookie and local storage both keep small bits of data in the browser. A cookie goes to the server with every request. Local storage stays in the browser and only your page's code reads it.
HTTP Cookie
A small piece of text a site stores in your browser, sent back on each visit.
A cookie is a small piece of text a website asks the browser to keep. The browser sends it back with every later request to that site. That is how a site remembers you are logged in or what is in your cart. A cookie can be set to expire, and flags like HttpOnly and Secure keep it safer. Cookies used to track people across sites are why many countries require a cookie notice.
Local Storage
A small store in the browser for a site's data. It stays after you close it.
Local storage is a small store in the browser for a site's data. The data is kept as text. Unlike a cookie, it is not sent to the server with each request. The data stays even after the browser is closed, until the site or the user clears it. Each site gets its own space, usually around 5 megabytes. Its cousin, session storage, is wiped when the tab closes.
In one line
- HTTP Cookie
- A small piece of text a site stores in your browser, sent back on each visit.
- Local Storage
- A small store in the browser for a site's data. It stays after you close it.