🍪💾 The Tale of Locky and Cookie: How the Web Remembers Stuff
Hello, coder! Today, I have a fun little story to tell you — about two clever helpers who live inside your browser. Their names? Locky and Cookie.
They work hard behind the scenes to remember things for you when you’re visiting websites.
Ready to meet them? Let’s go! 🚀
🧑🏽💻 Meet Locky the Locker (aka localStorage
)
Once upon a time in BrowserPalace, there was a helper named Locky. He looked like a big digital locker where you could keep your stuff — like your favorite color, your game score, or your website theme (dark or light).
Locky’s job was simple:
“I’ll remember things only on this computer — even if you leave and come back later!”
He’s fast, strong, and doesn’t bother anyone. But he has one rule:
“I never go to the office (the server). I stay right here with you!”
🍪 Meet Cookie the Messenger
Then there’s Cookie, a tiny but powerful helper. She’s like a message that’s written on a sticky note and carried to the teacher’s office (the server) every time you walk into class (open a page).
“Hey server, remember this student? Her name is Alice!”
Cookie may be small, but she’s very important. She helps websites know who you are, if you’re logged in, or what page you were last on.
🤔 So, What’s the Difference Between Locky and Cookie?
Let’s imagine our website is a school…
Feature | Locky the Locker 💾 | Cookie the Note 🍪 |
---|---|---|
Lives where? | In your browser locker | In your browser, but travels to the server |
Size | Big and strong — up to 5MB–10MB! | Tiny — only about 4KB |
Expires? | Nope. He remembers things forever (unless you clear them) | Yes, she can be told, “Forget this after 1 hour.” |
Goes to the server? | Never. He stays at school. | Always. She walks to the office with every request |
Best at | Remembering settings, themes, scores, notes | Remembering logins, sessions, and telling the server who you are |
🖍️ Let’s Play with Them!
🧪 Locky’s Code
Want to store something in Locky’s locker? Here’s how you do it:
localStorage.setItem('theme', 'dark');
Boom! You just told Locky:
“Hey, remember that I like dark mode!”
Later, you can ask him:
let theme = localStorage.getItem('theme');
He’ll reply,
“Dark!”
🧪 Cookie’s Code
Now, let’s give Cookie a note to carry:
document.cookie = "username=Alice; expires=Fri, 07 Jun 2025 12:00:00 UTC;";
Now every time you visit a new page on the same website, Cookie will say:
“The user’s name is Alice!”
The server can use that note to say,
“Welcome back, Alice!”
🧠 Who Does What?
Here’s a quick guide so you never forget:
You want to… | Use this |
---|---|
Remember game scores or settings | Locky 💾 |
Stay logged into a website | Cookie 🍪 |
Remember a dark/light theme | Locky 💾 |
Let the server know who’s visiting | Cookie 🍪 |
🎯 Quick Quiz Time!
Let’s see how well you know our two helpers:
1. Which one travels to the server with every request? 🅐 Locky 🅑 Cookie
2. Which one can store more data? 🅐 Cookie 🅑 Locky
3. Which one can expire automatically? 🅐 Locky 🅑 Cookie
4. What kind of data can both store? 🅐 Pictures 🅑 Videos 🅒 Text (like “Hello!”) 🅓 Games
5. You made a browser game. Where should you save the player’s score? 🅐 Cookie 🅑 Locky 🅒 A notepad 🅓 Flash drive
🎉 The Ending — But Not the End!
Now you know our two memory masters:
- Locky: the locker who keeps secrets in your browser.
- Cookie: the traveler who delivers messages to the server.
They both work together to make websites smart, friendly, and personal — just the way you like them.
So next time your browser remembers your theme or keeps you logged in — just smile and say:
“Thanks, Locky and Cookie!”