DEV Community

Cover image for Your Web App’s Data Can Disappear — Even If the User Never Cleared It
Frozen Blood
Frozen Blood

Posted on

Your Web App’s Data Can Disappear — Even If the User Never Cleared It

Here’s something many developers don’t realize until it hurts: the browser is allowed to delete your app’s stored data at any time — even if the user never clicked “Clear cache.”

LocalStorage. IndexedDB. Cache Storage.
None of them are guaranteed.

Let’s talk about why this happens, when it happens, and how to design around it.


The Browser Does Not Promise to Keep Your Data

Web storage APIs feel persistent, but they’re actually best-effort.

Browsers enforce:

  • Storage quotas
  • Eviction policies
  • Priority rules based on usage patterns

When space is needed, something has to go — and it might be your app.


The Silent Killer: Storage Eviction

Browsers may delete site data when:

  • Disk space is low
  • The site hasn’t been used recently
  • The user is in private / low-storage mode
  • The browser decides your data is “less important”

No warning.
No exception.
Just… gone.

Your app reloads like it’s the first visit.


“But I’m Using IndexedDB, Not LocalStorage”

Good instinct — but still not safe.

Approximate priority (simplified):

  1. User-engaged sites (frequently visited, interacted with)
  2. Persistent storage (explicitly requested)
  3. Everything else

If your app:

  • Is rarely opened
  • Lives behind a login
  • Stores large blobs (videos, offline data)

…it’s a candidate for eviction.


The One API Most Devs Don’t Use (But Should)

There’s a browser API called Persistent Storage.

JavaScript:

if (navigator.storage && navigator.storage.persist) {
  const isPersisted = await navigator.storage.persist();
  console.log("Persistent storage granted:", isPersisted);
}
Enter fullscreen mode Exit fullscreen mode

If granted:

  • Your data is much less likely to be evicted
  • The browser treats it like important app data

Most apps never request this — and many devs don’t know it exists.


How Browsers Decide Who Loses Data

It’s not random. Browsers look at:

  • How often the user visits the site
  • Whether the site is installed (PWA)
  • User interaction signals
  • Storage pressure on the device

That’s why:

  • Offline-first apps survive longer
  • Background tools disappear faster
  • “Internal dashboards” get wiped unexpectedly

Real-World Failure Mode

This usually shows up as:

  • “Some users got logged out”
  • “Drafts randomly disappeared”
  • “Offline mode stopped working”
  • “It only happens on mobile”

And it’s brutal to reproduce.


Practical Defensive Strategies

  • Treat browser storage as a cache, not a database
  • Sync critical data to a backend
  • Request persistent storage for offline apps
  • Detect missing state and recover gracefully
  • Never assume stored data will exist tomorrow

If losing the data breaks your app, you designed it too optimistically.


Conclusion / Key takeaway

Browser storage feels permanent — but it isn’t. Once you accept that, you start building web apps that are more resilient, predictable, and user-friendly.

Discussion question:
Have you ever debugged “random data loss” in a web app — and later realized the browser was the culprit?

If you want tomorrow’s post to be AI, frontend-specific, or pure dev horror stories, tell me and I’ll tune it.

Top comments (0)