Why it matters
- Security: a session that doesn’t end on logout, or a token readable by any script, can hand someone else your account.
- Privacy and law: in the EU and UK, tracking cookies need consent. A “Reject” button that doesn’t actually reject is a legal risk, not just a bug.
- Money: a cart that disappears after login, or a checkout that logs you out halfway, loses sales.
- Trust: seeing someone else’s cart or name on a shared computer is the kind of bug that ends up in the news.
Where a website keeps data
| Storage | Lifetime | Sent to the server automatically? | Readable by page JavaScript? | Typical use |
|---|---|---|---|---|
| Cookie | Until it expires, or until the browser closes (session cookie) | Yes, with every request to its domain | Yes, unless HttpOnly | Login session, consent choice, language, analytics IDs |
| localStorage | Forever, until the site or user deletes it | No | Yes | Guest cart, theme, “don’t show again” flags |
| sessionStorage | Until the tab is closed (survives reloads) | No | Yes | Form drafts, one-time banners, checkout steps in one tab |
| IndexedDB | Forever, until deleted | No | Yes | Large structured data: offline mode, cached messages, files |
| Cache Storage / HTTP cache | Until evicted or cleared | (It replaces requests) | Cache Storage: yes | Offline pages (service workers), images, scripts |
The sizes differ too: a cookie holds about 4 KB, localStorage and sessionStorage about 5 MB per site, and IndexedDBIndexedDBA database inside the browser for larger structured data, often used for offline features.Open in glossary → can hold far more. You don’t need to memorize numbers, but you should know which one a feature uses, because that decides what survives a reload, a closed tab or a logout.
Check this part
Which kind of storage is sent to the server automatically with every request?
Where does a login token belong?