Offline web app data: browser storage limits and eviction
Short answer: Data your web app stores in the browser, in IndexedDB, the Cache API or local storage, isn't guaranteed to stay there. By default it's "best-effort": the browser can delete it when the device runs low on space, and Safari can clear script-created data for sites people haven't interacted with for seven days of browser use. Treat browser storage as a cache, sync anything important to your server, check how much space you have with navigator.storage.estimate(), and ask for persistent storage with navigator.storage.persist() when the data really matters.
Why this catches business apps out
Offline-capable web apps are popular for field work: inspection checklists, stocktakes, delivery confirmations, job notes on sites with poor coverage. A New Zealand contractor's crew might fill in forms on a tablet all morning in a rural area and sync in the afternoon. If the app assumes the browser will keep that data indefinitely, a full device or a privacy feature can quietly wipe hours of work.
The fix isn't complicated, but it needs to be designed in.
How browsers decide what to keep
MDN's guide to storage quotas and eviction explains that data for an origin (a scheme, host and port, such as https://app.example.co.nz) is stored in one of two modes:
- Best-effort, the default. It persists as long as the origin is under its quota, the device has enough space and the user doesn't clear it.
- Persistent. The browser keeps it even under storage pressure, unless the user removes it.
The WHATWG Storage Standard, which browsers implement, defines the same two modes and says local storage buckets start as best-effort.
Under storage pressure, MDN says browsers use a least recently used policy: they delete data from the least recently used origin first, then the next, until enough space is free. A tablet used for photos and video can hit this sooner than you'd expect.
Proactive eviction in Safari. MDN notes that Safari deletes script-created data for an origin when cross-site tracking prevention is on and there has been no user interaction, such as a click or tap, in the last seven days of browser use. Server-set cookies are exempt. An app used only once a fortnight on an iPad could lose its offline data between visits.
All or nothing. When an origin's data is evicted, MDN explains that all of it goes at once, IndexedDB and Cache API together, to avoid inconsistency. You won't be left with half a database, but you may be left with nothing.
How much can you store?
Limits vary by browser and device, and browsers don't publish one fixed number for IndexedDB. MDN does document a small fixed limit for the simpler Web Storage API: up to 5 MiB each for local storage and session storage per origin, after which browsers throw a QuotaExceededError. That's one reason not to keep offline records in local storage.
To see where you stand, call:
const { usage, quota } = await navigator.storage.estimate();
MDN cautions that this returns an estimate, not an exact figure. Use it to warn users before they start a big offline task, for example "This device is low on space for offline jobs."
Asking for persistent storage
The Storage Standard describes navigator.storage.persist() as the simple way to make storage persistent: it requests permission and switches the storage to persistent once granted.
Browsers handle the request differently. MDN explains that Firefox shows the user a prompt, while Safari and most Chromium-based browsers approve or deny automatically based on the user's history of interaction with the site, without a prompt. In practice:
- Call it after the user has engaged with your app, for example when they enable offline mode, rather than on first load.
- Check the result.
navigator.storage.persisted()tells you whether it's already granted. - Don't rely on it alone. Even persistent data can be cleared by the user.
Design for loss
Sync early and often. Send each completed record to your server as soon as there's a connection, rather than batching a whole day.
Show sync status. A visible "3 jobs waiting to upload" counter tells staff not to clear the browser or swap devices yet.
Keep server truth. Treat the browser copy as a working cache. Anything that matters for invoicing, compliance records or customer history lives on the server.
Handle quota errors. Wrap writes in error handling and tell the user what to do if storage is full.
Detect eviction. On start-up, check for a marker your app writes. If it's missing but the user was signed in, the data was cleared; reload from the server and explain what happened.
Use the right storage. IndexedDB for structured records, the Cache API for files and responses, and avoid local storage for anything big or important.
Testing
- Use your browser's developer tools to clear site data and confirm your app recovers gracefully.
- Fill a test device with data to see how your app behaves under storage pressure.
- Test on an iPad or iPhone in Safari over more than a week without opening the app, if offline use matters for those devices.
A worked example
A hypothetical Hamilton fencing company uses a web app for site measurements. Staff save measurements offline and upload at the end of the week. After a crew's tablet storage fills with photos, a week's measurements vanish. The developer changes the app to upload each job as soon as it's saved and a connection exists, adds a visible queue of unsynced jobs, requests persistent storage when staff turn on offline mode, checks estimate() before large photo uploads, and shows a recovery message if local data disappears.
FAQ
Is this a bug in the browser?
No. Browsers manage limited space on users' devices and protect privacy. Apps need to expect it.
Does installing the app as a PWA change things?
Behaviour can differ by browser and platform. Check current documentation for the browsers your staff use, and still design for loss.
Will clearing cookies delete IndexedDB too?
Clearing site data usually removes all storage for the site, including IndexedDB.
Should we just build a native app?
Native apps have their own storage rules but generally more control. Choose based on your wider needs, not storage alone.
If your offline web app has lost data or you're planning one for field staff, tell us how it stores data today. Our page on web app development in Vienna covers how we plan and build business web apps.