๐ช Cookies Explained Like You're 5
Source: Dev.to
The Club Wristband
You go to a club. Pay at the door. Get a wristband.
Now you can:
- Leave and come back
- Staff knows you already paid
- No need to pay again
Cookies are digital wristbands!
How They Work
- You visit a website
- The website gives your browser a โcookieโ (a small piece of data)
- Next time you visit, the browser sends the cookie back
The website recognizes you!
Visit 1: "Here's your cookie: user=alex"
Visit 2: Browser shows cookie โ "Welcome back, Alex!"
What Cookies Store
- Login status (so you stay logged in)
- Shopping cart items
- Preferences (dark mode, language)
- Tracking info (ads use this)
Types
| Type | What it means |
|---|---|
| Session | Typically lasts for the current browsing session (but some browsers can restore them) |
| Persistent | Has an expiry time/date; can last days/weeks/months |
| Thirdโparty | Set by a different site than the one youโre visiting (often used for ads/analytics) |
Privacy Concerns
Cookies can be used for tracking across websites. Thatโs why many sites ask:
โDo you accept cookies?โ ๐ช
In One Sentence
Cookies are small pieces of data websites store in your browser to remember who you are and your preferences.