Core question: How does a website remember who you are, what is in your shopping cart, or that you prefer Dark Mode after you refresh the page?

🍏 Tutor’s Notes

When we looked at the Request ↔ Response Cycle, we saw how a client asks a server for data and the server replies. Here is a quirk about that cycle that surprises almost every beginner: by default, HTTP is completely stateless (it has no memory).

As far as basic HTTP is concerned, every time you click a link or refresh a page, you are a total stranger meeting the server for the very first time. Without some way to remember state on your device:

While websites store permanent account data in a database on the Server, reaching across the internet just to check if you prefer Dark Mode—or to figure out which user is sending a request—needs help from the client. To solve this, browsers provide Browser Storage: built-in digital compartments right on your device where websites can save data for instant access.

The Analogy: Wristbands, Notebooks, Sticky Notes, and Filing Cabinets

Browsers give developers several different storage compartments because different types of data have different rules. Think of them like four everyday items:

Deep Dive: The Core Storage Mechanisms

1. Cookies

Invented in 1994 so early online shops could build working shopping carts, Cookies are the oldest storage mechanism on the web. Despite the name, a cookie is just a tiny snippet of text saved in your browser.