Back to articles
πŸ” localStorage vs sessionStorage vs Cookies (Complete Frontend Guide)

πŸ” localStorage vs sessionStorage vs Cookies (Complete Frontend Guide)

via Dev.to WebdevPawar Shivam

When building authentication, saving user preferences, or managing sessions, developers often choose between localStorage , sessionStorage , and Cookies . But the real difference appears in network behavior, security, and persistence . Let’s break it down. 🧠 Storage Architecture (Simple Diagram) Browser β”‚ β”œβ”€β”€ localStorage β”‚ └── Stored in browser β”‚ └── NOT sent with network requests β”‚ β”œβ”€β”€ sessionStorage β”‚ └── Stored per tab session β”‚ └── Removed when tab closes β”‚ └── Cookies └── Stored in browser └── Automatically sent with HTTP requests Example HTTP Request: GET /api/profile Host: example.com Cookie: sessionId=abc123 Only cookies travel with network requests automatically . 🟒 localStorage Stores data without expiration . πŸ“¦ Size ~5–10MB depending on browser 🌐 Network Not sent to server automatically πŸ”’ Security Accessible via JavaScript β†’ vulnerable to XSS attacks βœ… Pros β€’ Large storage β€’ Persistent data β€’ Simple API β€’ Good for UI caching ❌ Cons β€’ Not secure for sensitive data β€’ Vulnerab

Continue reading on Dev.to Webdev

Opens in a new tab

Read Full Article
2 views

Related Articles