Shahin

localStorage

Advanced
Updated Jul 11, 2026 Shahin editorial 2 min read
PronunciationEN/ˈloʊkəl ˈstɔːrɪdʒ/

localStorage is a small in-browser data store that keeps information on the user's device, scoped to that origin, and unlike a cookie is not sent to the server automatically with each request.

localStorage and cookies are two browser stores with different uses. A cookie goes to the server automatically with every request, so it suits things the server must know (like a login session) but adds weight to each request. localStorage stays on the device and is used only when JavaScript reads it, so it is lighter and better suited to holding client-side identifiers and preferences. In analytics, localStorage is the natural place to keep a visitor identifier so it persists across visits. But it has two limits: it is scoped to one origin, so it is not shared across domains and sometimes not even across subdomains, and it is lost if the user clears browser data or is in a private window. This is why mature tools keep the identifier in both localStorage and a cookie, so if one is cleared the other bridges.