Member-only story
Cookie | Local Storage | Session Storage
4 min readMar 10, 2024
Cookie vs Local Storage
Storage Limit:
- Cookies: Limited to about 4 KB of data. This limit is shared among all cookies for a given domain.
- Local Storage: Offers significantly more storage space, usually around 5 MB per domain.
Data Handling:
- Cookies: Data is sent with every HTTP request to the domain, including both page requests and asset requests. This can impact performance, especially when dealing with large amounts of data.
- Local Storage: Data is not automatically sent with every HTTP request. It needs to be explicitly read and written by the web page, making it a better choice for larger amounts of data that don’t need to be transmitted with every request.
Expiration:
- Cookies: Can have an expiration time set. They may be session cookies (stored until the browser is closed) or persistent cookies (stored for a specific duration).
- Local Storage: Data persists until explicitly deleted by the web page or cleared by the user.
Accessibility:
- Cookies: Sent with every HTTP request, including both page requests and asset requests. They can be accessed on the server side.