Wirebook › Lesson 18 of 18
What is a cookie on a website?
Websites have terrible memories. Every time your browser asks for a page, the website has no idea it has ever met you before. So how does a shop remember what's in your basket, or a game remember you're logged in? With a cookie: a tiny note the website asks your browser to keep and hand back next time. Here you get to watch the cookie jar fill up, then follow a sneaky tracker from site to site.
How a cookie works
- You visit. Your browser asks for the page. The website doesn't know who you are.
- The website hands over a note. Its reply includes a line like
Set-Cookie: basket=2-pancakes, which asks your browser to keep that note. - Your browser hands it back. On every later visit to that same website, the browser adds
Cookie: basket=2-pancakesto its message. Now the website "remembers" you. - Some notes vanish, some stay. A session cookie is thrown away when you close the browser. A cookie with an expiry date (like "remember me for 30 days") stays until then, or until you clear it.
First-party and third-party cookies
A first-party cookie comes from the website you're actually on, like the café remembering your basket. Mostly helpful. A third-party cookie comes from some other company whose bits are tucked inside the page: an advert, a "like" button, a video player. Because the same company is tucked inside thousands of websites, its one cookie can link your visits together into a list of what you're interested in. That's how an advert for penguin pancake pans can follow you from a recipe site to a zoo site.
That's why many browsers now block third-party cookies or give the ad company a separate jar for every website, so the notes can't be joined up. The ad company sees three strangers instead of one person.