TGViewer
Web Development Web Development @web_dev_bds Β· 4.44K subscribers
Post #819 746
πŸš€ Cookies vs LocalStorage vs SessionStorage

All store data in the browser. 
But they differ in size, lifetime, and usage.


1️⃣ Cookies πŸͺ

Sent with every HTTP request.

➀ Size: ~4KB 
➀ Lifetime: Set by expiry 
➀ Best for: Authentication, sessions 
➀ Risk: Sent on every request 

Example:
Set-Cookie: user=123;

2️⃣ LocalStorage πŸ—„οΈ

Stored in browser permanently.

➀ Size: ~5–10MB 
➀ Lifetime: Until manually cleared 
➀ Best for: Preferences, themes 
➀ Risk: Vulnerable to XSS 

Example:
localStorage.setItem("theme", "dark");


3️⃣ SessionStorage ⏳

Stored per browser tab.

➀ Size: ~5MB 
➀ Lifetime: Until tab closes 
➀ Best for: Temporary form data 

Example:
sessionStorage.setItem("step", "2");


πŸ’‘ Key Difference

Cookies β†’ Small & sent to server 
LocalStorage β†’ Persistent 
SessionStorage β†’ Temporary 

Choose based on security and data lifetime.
  • ❀ 3
  • πŸ™ 1
More from @web_dev_bds
  1. Oct 13, 2026Docker vs Kubernetes
  2. Oct 12, 2026Post #1054
  3. Oct 11, 2026CSS Tip Stop centring tooltips with πšπš›πšŠπš—πšœπš•πšŠπšπšŽ: -𝟻𝟢%. near the edge of the scree…
  4. Oct 9, 2026JavaScript CheatSheet
  5. Oct 8, 2026πŸ“•Pro tip if you're using Postgres: Set `application_name` in your app's DB connector/ORM/…
  6. Oct 7, 2026πŸš€ Beginner β†’ Developer: What to Learn in 6 Months Want to become job-ready but don't know…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook β†’Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 β†’