Lingua-e
← Errors
JavaScript

localStorage Quota Exceeded: What It Means and How to Fix It

Error reference

localStorage Quota Exceeded

Language

JavaScript

Severity

Medium

When it happens

A QuotaExceededError (DOMException) is thrown when a write to localStorage or sessionStorage would exceed the browser's storage limit, typically around 5 MB per origin.

Potential fixes

Wrap localStorage.setItem() in a try/catch for QuotaExceededError. Prune old or large items before writing. For larger data, use IndexedDB which has no hard size limit. Consider a cache eviction strategy (LRU, TTL) to keep storage size bounded.

Deep dive

A QuotaExceededError (DOMException) is thrown when a write to localStorage or sessionStorage would exceed the browser's storage limit, typically around 5 MB per origin. The error name varies slightly across browsers.

Why it happens

  • Storing large JSON objects or base64-encoded images in localStorage.
  • Accumulating many small items over time that together exceed the quota.
  • Multiple tabs or the same app over time filling up the storage.

Potential fixes

Wrap localStorage.setItem() in a try/catch for QuotaExceededError. Prune old or large items before writing. For larger data, use IndexedDB which has no hard size limit. Consider a cache eviction strategy (LRU, TTL) to keep storage size bounded.

Examples

JavaScript

Code that triggers the error

const bigData = "x".repeat(10 * 1024 * 1024); // 10 MB
localStorage.setItem("cache", bigData);

Error output

DOMException: Failed to execute 'setItem' on 'Storage': Setting the value of 'cache' exceeded the quota.

Fixed code

function safeSetItem(key, value) {
  try {
    localStorage.setItem(key, value);
  } catch (e) {
    if (e.name === "QuotaExceededError") {
      localStorage.clear();
      localStorage.setItem(key, value);
    }
  }
}

Practice in English

How would you explain a localStorage Quota Exceeded to a fellow dev? Choose the right phrase:

"I hit an error...

Ready to practice your English at work?

Lingua-e has interactive exercises built around real developer conversations: standups, code reviews, retrospectives, and more. Practice until it comes naturally.

Try Lingua-e for free