Senior
How does cookies differ from cache?
sobes.tech AI
Answer from AI
Cookies and cache are different mechanisms used by browsers for different purposes.
Cookies:
- Store small data (e.g., sessions, user settings).
- Sent to the server with each HTTP request to the corresponding domain.
- Used for authentication, maintaining state, and personalization.
Cache:
- Stores copies of resources (HTML, CSS, JS, images) to speed up page loading.
- Not sent to the server, used locally by the browser.
- Helps reduce traffic and speed up page rendering.
Example: when you visit a website, cookies may store your session ID, and cache stores saved styles and scripts to avoid re-downloading them on repeat visits.