Building Your Learning Module...
Getting things ready for you!
Find videos you like?
Save to resource drawer for future reference!
Cookies are small text files stored by the browser that can hold data up to 4KB per cookie. They are automatically sent with every HTTP request to the same domain, making them useful for authentication, tracking, and storing user preferences.
Automatically included in HTTP requests to the server
Can be set to expire at a specific time or when browser closes
Can be scoped to specific domains and URL paths
| Attribute | Description | Example |
|---|---|---|
name=value | Cookie name and value (required) | username=john |
expires | Expiration date (UTC format) | expires=Wed, 31 Dec 2025 |
max-age | Lifetime in seconds | max-age=3600 |
domain | Domain that can access cookie | domain=example.com |
path | URL path where cookie is valid | path=/admin |
secure | Only sent over HTTPS | secure |
httpOnly | Not accessible via JavaScript | httpOnly |
sameSite | CSRF protection (Strict, Lax, None) | sameSite=Strict |
secure, httpOnly, and sameSite attributes for sensitive cookies to prevent XSS and CSRF attacks.Essential functions for cookie manipulation
Production-ready cookie handling with security options
| Feature | Cookies | localStorage | sessionStorage |
|---|---|---|---|
| Capacity | ~4KB | ~5-10MB | ~5-10MB |
| Sent to Server | Yes (automatic) | No | No |
| Expiration | Configurable | Never (manual) | Tab close |
| Scope | Domain/path | Origin | Tab/window |
| Best For | Auth tokens, tracking | User preferences | Form data, temp state |
Automatically sent with every HTTP request
Maximum 4KB per cookie
Use secure, httpOnly, and sameSite flags
Set custom expiration dates