Which storage is sent to the server automatically with every matching request?
Options
- localStorage
- sessionStorage
- Cookies (Correct option)
- IndexedDB
Answer
Cookies
Why
Cookies are attached by the browser to every request to their domain, which is why sessions use them. They are small (about 4 KB).
localStorage (permanent) and sessionStorage (per tab) stay in the browser; JavaScript must read them and send them explicitly. Any script on the page can read them, so they are risky for auth tokens.
IndexedDB is a larger in-browser database.
Remember
Only cookies travel automatically with requests.