Loading...
Loading...
By continuing to use the platform, you accept the terms of the Privacy Policy and the use of cookies.
In browser there are several types of built-in data storage that can be used to save user state, cache, settings, etc.
| Storage | Volume | Availability | Lifetime | Sent to Server | Support |
|---|---|---|---|---|---|
| Cookie | ~4 KB | Server and client | Depends on Expires | Yes | All browsers |
| LocalStorage | ~5–10 MB | Client only | Until deletion | No | All browsers |
| SessionStorage | ~5–10 MB | Client only | While tab is open | No | All browsers |
| IndexedDB | 100+ MB | Client only | Until deletion | No | All browsers |
Set-Cookie header or document.cookiedocument.cookie = "theme=dark; path=/; max-age=3600";
localStorage.setItem("theme", "dark");
const theme = localStorage.getItem("theme");
localStorage.removeItem("theme");
localStorage, but lives only within one tabsessionStorage.setItem("step", "2");
sessionStorage.getItem("step");
const db = indexedDB.open("MyDB", 1);
Easier to use via wrappers:
| Scenario | Recommended Storage |
|---|---|
| Authorization, tokens | cookie (with Secure + HttpOnly flags) |
| User settings | localStorage |
| Temporary data | sessionStorage |
| Offline data cache, PWA | indexedDB |
Security:
Never store access tokens in LocalStorage or SessionStorage if they can be stolen via XSS. Use HttpOnly cookie.
cookie for transferring between client and serverlocalStorage for permanent client datasessionStorage for temporary, one-time dataIndexedDB for complex and large storage