Course contentsShow
← Web Development
Lesson 823 of 2,98214. Browser StorageFree lesson

Persistence and Durability

Evaluate persistence guarantees, expiration behavior, and user control over data retention per storage type.

Persistence and Durability

You'll learn how long different browser storage mechanisms keep your data and what can cause data loss.

What Persistence Means

Just like saving a document on your computer, browser storage isn't all equally reliable. Some storage types keep data "forever" (until you manually delete it), while others vanish the moment you close a tab. Understanding these guarantees helps you choose the right storage for the right job.

Storage Type Persistence

localStorage persists indefinitely — data survives browser restarts, computer reboots, and stays until the user explicitly clears it or your code removes it. Think of it as writing in permanent marker.

sessionStorage lasts only for the current tab session. Close the tab? Gone. It's like a sticky note you throw away at the end of the day.

Cookies persist based on their Max-Age or Expires attribute. Without these, they're session cookies (like sessionStorage). With an expiration date, they can last years — or disappear tomorrow.

IndexedDB behaves like localStorage — it persists indefinitely and survives restarts.

Cache API also persists indefinitely, but it's more vulnerable to browser cleanup when disk space runs low.

What Can Erase Data

All storage types share common threats:

  • User action: Clearing browsing data, using private/incognito mode, or storage management tools
  • Browser cleanup: When disk space is scarce, browsers may automatically purge Cache API or even IndexedDB
  • Storage limits: Exceeding quotas can prevent new writes or trigger eviction

Unlike cookies (which servers can restore), client-side storage has no automatic backup — if it's gone, it's gone.

Key Takeaway: localStorage and IndexedDB offer the strongest persistence guarantees, sessionStorage is intentionally temporary, cookies depend on expiration settings, and all storage types remain vulnerable to user deletion or browser cleanup policies.