
Browser Storage and Offline: The Client Data Layer
Web apps that cache reads or queue writes store data on the device whether or not anyone designed it. A field guide to the five client stores, the eviction physics behind them, and the offline arc to sync.
TL;DR: A web app that caches reads, keeps unsaved drafts, or queues writes stores that data on the user's device, whether or not anyone designed where it goes. This guide gives you the floor-to-ceiling map of the five client stores, the quota-and-eviction physics behind them, the offline arc from read cache to sync and conflict, and an honest account of what data on someone else's disk can never promise.
A permanent layer, not a niche
Open the storage panel of a web application you use daily and look at what is stored there. Some of it was placed deliberately; much of it accumulated because the platform makes storing things easy and forgetting to design that storage easier still. Cached API responses, a half-finished form, the theme the user picked earlier, a mutation waiting for the network to come back — all of it lands somewhere on the device. The question is never whether your app has a client data layer. It is whether anyone shaped it on purpose.
This layer has proven unusually durable. Frameworks arrive and depart, but IndexedDB has been the structured storage floor of the browser for over a decade, and the disciplines that surround it — reasoning about quotas, surviving eviction, reconciling a mutation made offline — transfer intact across every stack an engineer will touch. Learning this layer is not learning a library. It is learning a set of constraints the platform has held stable through many library generations, which is exactly the kind of knowledge that keeps paying out.
The framing decision an IC actually faces sits underneath every feature that touches stored data, and it has three answers rather than one. Is this feature merely faster with a cache in front of it, so the network is an optimization? Does it need to tolerate a lost connection, so disconnection is an expected state rather than an error? Or does it need to work primarily from local data, so the server becomes a synchronization target rather than the source of truth? Those are three different engineering commitments with three different cost curves, and choosing among them deliberately is the first act of designing this layer well.
The storage map in one view
The browser offers five places to put data, and a misfit comes from reaching for the familiar one instead of the fitting one. The table below is the whole territory at a glance; the decision depth — which store for which data shape — belongs to the storage-options foundation, and the physics behind the rows belongs to the quota-and-eviction foundation.
| Store | What it is for | What it must never hold |
|---|---|---|
| Cookies | Small server-bound state replayed as a request header on matching requests (sessions, server-read flags); browsers may withhold it, for example on third-party requests | Application data, anything the server does not need on those requests, secrets in readable form |
| localStorage / sessionStorage | A handful of small synchronous strings — preferences, last-selected UI state; sessionStorage scopes to one tab | Application datasets, anything a worker needs, anything past trivial size, security-sensitive values |
| IndexedDB | Structured records with indexes and transactions, worker-accessible, large quota — the structured floor for application data | Data whose query shapes need real joins and ad hoc SQL; that is the ceiling conversation |
| Cache API | Request/response pairs, when the unit of data is literally an HTTP response | General key-value data; the HTTP-caching strategy built on it is a separate craft |
| OPFS | Raw byte files in an origin-private filesystem — the substrate for database engines and large binaries | Data you need the user's file manager to see; casual small values that IndexedDB handles more simply |
The ceiling deserves naming once, because it surprises engineers who last checked years ago: an SQLite database compiled to WebAssembly and backed by OPFS gives you real relational queries — joins, indexes, a query planner — running inside the browser tab. It is official, it is real, and it is justified only under specific conditions that its own article covers. The point of the map is that the floor and the ceiling are the same platform seen at two altitudes, and the honest default sits much closer to the floor than a WebAssembly database demo makes it feel.
The physics: quotas, eviction, persistence
Before choosing a store, an engineer has to internalize the physics behind the stores, because it inverts an assumption carried over from server work. On the server, data you write stays written until you delete it. In the browser, everything script-writable is best-effort by default: under storage pressure the browser may evict an origin's best-effort data without asking the user. Do not count on your app hearing about it: the Storage Standard says browsers should avoid clearing a storage bucket while script that can access it is running, unless the user instructs otherwise, so plan to discover an eviction on the next start (an IndexedDB connection that is open when its storage is cleared does receive a close event). Storage is a lease, not a deed. That single reframing changes every downstream decision.
In most cases quota is managed per origin (in best-effort mode Firefox also applies a 10 GiB group limit to all origins of the same site), and each browser sets it by its own rules based on total disk size rather than free space; the WHATWG Storage Standard says quota must not be a function of the available storage space on the device. That means the honest answer to "how much can I store" is "it varies by browser, device, and disk." The Storage API's navigator.storage.estimate() reports usage and quota as estimates — deliberately imprecise in some browsers — never as a guarantee of writable headroom (as of Nov 2026, per MDN's storage quotas and eviction criteria; check the current figures before relying on them).
One eviction rule matters more than the rest for any data layer meant to survive. When cross-site tracking prevention is on, Safari's Intelligent Tracking Prevention deletes cookies created in JavaScript and all other script-writable storage after seven days of browser use with no user interaction on the site, and the first-party domain of a web app added to the home screen is exempt (as of Nov 2026, per WebKit's tracking-prevention documentation and MDN). A user who visits once and returns after a long gap may find the local database empty — not corrupted, empty — and an app that treats absent data as a crash rather than an expected state will greet them with a broken screen.
There is a lever, and it is a request rather than a right. navigator.storage.persist() asks to exempt the origin from best-effort eviction; browsers grant it by different rules, some silently on engagement heuristics and some by prompting, and code must treat a refusal as normal. None of this exempts data from the user clearing it or the OS resetting a profile. The design consequence follows in one sentence and recurs through this whole topic: classify every piece of stored data as re-fetchable, reconstructible, or unrecoverable, and never let the unrecoverable class live only in best-effort storage.
The offline arc
"Offline support" is not one feature. It is an arc of increasing responsibility, and naming its stages keeps a team honest about where their feature actually sits.
The read side is the easy half. Data cached on the device — server entities the user already loaded — lets the interface render without a round-trip. If the network is gone, the user still sees their last-known state instead of a spinner. Nothing about a read cache carries risk to the user's data, because the server still holds the truth.
The write side is where responsibility enters. A mutation made while disconnected has nowhere to go, so it must be captured in a durable outbox on the device, retried with idempotency when the connection returns, and reconciled with whatever the server did in the meantime. Lose that outbox to an eviction and you have lost the user's work — which is exactly why the unrecoverable classification exists and why the write-queue and sync articles are separate, careful treatments rather than footnotes.
Sync turns a cache into a replica, and replicas that both changed will conflict. How a conflict resolves — last-writer-wins, field-level merge, a prompt to the user — is a product decision, not a library default to accept blindly. A maturing ecosystem of sync engines now packages parts of this arc as infrastructure, and how much of it differs by engine: PowerSync's documentation describes apps that keep working offline, with an upload queue for client writes and guidance on conflicts; ElectricSQL's documentation says it does read-path sync out of Postgres and leaves the write path to the application; and Zero's documentation says it does not support offline writes. They are named here as market reality rather than ranked, and the fact that Replicache's lineage gave way to Zero is itself evidence that this landscape changes quickly (as of Nov 2026, per each vendor's documentation; re-verify vendor capabilities before committing to one). The spectrum stated plainly: offline-tolerant, offline-first, and local-first are three increasing commitments with three increasing costs, and many enterprise features belong on the left half of that line, not the fashionable right end.
How the work decomposes across this topic
This guide is the routing frame; the depth lives in the articles that surround it, and it helps to see the decomposition as a whole before diving into any one piece.
Two foundations sit under everything. The storage-options decision answers "where should this data live," and the quota-and-eviction physics answers "when is the browser allowed to take it back." Every other article assumes both. From there this topic works outward through IndexedDB in practice — schema, versioning, the wrappers worth using — and up to the OPFS-and-SQLite ceiling for the workloads that earn relational queries. Client data migrations handle the reality that your on-device schema will change under users who are offline. The offline write queue, local-first architecture, sync-engine evaluation, and conflict resolution together compose the write-and-sync half of the arc. Multi-tab coordination addresses the same origin's data being touched by three open tabs at once. And storage debugging covers reproducing eviction and quota exhaustion deliberately, so you find those states in development rather than in a user's bug report.
Each article is a decision artifact plus the mechanics to execute it. Read them as a sequence when you are building this layer from scratch, or jump to the one your current feature needs — the map holds either way.
What the client data layer does not give you
A guide that only described the capabilities would be selling something, so the limits get their own section, stated as plainly as the physics.
It is not durable storage unless data is both persisted and synced. The user can clear it, the browser can evict it, and the OS can wipe it, so the correct mental model treats local data as a cache until a server copy exists. It is not a vault, either: Web Storage, IndexedDB, the Cache API, and OPFS are readable by any script running on the origin (cookies marked HttpOnly are withheld from APIs that expose cookies to scripts, such as document.cookie, although HttpOnly does not stop requests that script initiates from carrying them), encryption-at-rest is not a property the web platform guarantees to your application, and the client-side security threat model is its own body of literature — secrets and high-sensitivity data do not belong here. For many enterprise workloads the server remains the system of record; local-first inverts that relationship only for the specific workloads that earn the inversion, and pretending a feature earns it when it does not is how teams end up rebuilding a database badly inside a browser tab.
One last honesty applies to the engineer's own machine. The quotas you observe and the eviction you can or cannot reproduce on your workstation are one device's reality. The fleet of real user devices — older phones, constrained disks, private-browsing sessions, Safari's seven-day clock — varies far more widely than any single development environment shows. Design for the constrained case, measure against it, and treat your own machine as the best case rather than the representative one. The client data layer is a genuine and permanent part of the platform; building on it well means respecting exactly what it is and refusing to lean on what it is not.