The Limits of Local Storage: Capacity, Deletion Timing, and Safety Explained

LocalStorage is limited to around 5MB and may be deleted automatically on iPhones. This guide explains storage limits, why data disappears, and how to use localStorage safely.

Contents

LocalStorage is commonly used in modern web apps to store user settings and small pieces of data directly on the device. But many developers (and users) are surprised to learn that localStorage has clear limitations, strict capacity limits, and unexpected deletion behaviors—especially on iPhone.

This article explains localStorage’s storage limits, why data sometimes disappears, how browsers decide what to delete, and how to use localStorage safely.

What Is Local Storage? (Quick Refresher)

localStorage is a simple browser-based storage system used to save small amounts of data on the user's device. It’s commonly used for:

Unlike cookies, localStorage does not expire automatically. But that does not mean it stays forever—especially on iOS.

How Much Can You Store? Actual Capacity Limits

The biggest limitation: localStorage is very small. Most environments allow only around 5MB.

Browser / Platform Approx. Capacity
iOS Safari ~5MB
Android Chrome 5–10MB
iOS PWA (standalone) ~5MB
Desktop Browsers 10MB around

localStorage is meant for very small configuration data—not large JSON files, images, or app datasets.

If you exceed the limit, the browser throws a QuotaExceededError and the save operation fails.

The iPhone Problem: Safari May Delete Data Automatically

Here is the most important warning:

iOS may delete localStorage without warning when device storage is low.

Why? iOS Storage “Eviction” System

When iPhone storage becomes tight, iOS automatically clears:

This means a web app may suddenly “reset” because its localStorage was wiped by the OS.

Data That Tends to Be Deleted

iOS is aggressive with storage cleanup, and localStorage is one of the easiest targets.

Which Is More Stable: Cookies or Local Storage?

Short answer: Most volatile → localStorage More persistent → cookies (depending on expiration)

Reasons:

Developers should not rely on localStorage for critical data.

Weaknesses of Local Storage

How to Use localStorage Safely

1. Keep stored data extremely small

Only store settings or simple flags; compress JSON if necessary.

2. Store “non-critical” data only

Never store authentication tokens or important user data.

3. Prepare a recovery mechanism

If localStorage is cleared, the app should be able to recreate or refetch data.

When localStorage Is a Good Fit / Bad Fit

✔ Good Fit

✘ Bad Fit

Conclusion

localStorage is convenient, but understanding its limitations is essential. Think of it as a simple “memo pad,” not a long-term storage solution.

The Safari Cache Delete Technique Every Web Tool Developer Uses — Why “Clear All” Can Make Things Worse

Safari’s cache shouldn’t be cleared entirely—doing so can break logins and still leave hidden WebClip cache behind. This guide explains the precise, developer-proven method that reliably clears Safari cache for a single website without affecting everything else.

Ojach

Writing about PWAs and web development.

← Back to articles