The Limits of Local Storage: Capacity, Deletion Timing, and Safety Explained
Last updated: 2026/02/01
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:
- Saving UI preferences
- Keeping temporary flags
- Preserving PWA setup states
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.
👉 How to Build a PWA: A Beginner-Friendly Guide to manifest.json, Service Workers, and Home Screen Setup
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:
- App cache and temporary files
- Browser cache and localStorage
- PWA storage (which is even more fragile)
This means a web app may suddenly “reset” because its localStorage was wiped by the OS.
Data That Tends to Be Deleted
- PWA standalone mode data
- localStorage from sites not opened for a long time
- localStorage containing larger amounts of stored data
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:
- Safari may auto-delete cookies because of ITP (privacy rules)
- iOS may delete localStorage because of storage cleanup
- Neither is guaranteed to last forever
Developers should not rely on localStorage for critical data.
Recommended Safe Alternatives
- Use IndexedDB for structured, persistent data
- Backup data to server when possible
- Store only lightweight settings in localStorage
Weaknesses of Local Storage
- ❌ Very small capacity (around 5MB)
- ❌ Easily deleted on iPhone when storage is low
- ❌ Not synced across devices
- ❌ Vulnerable to XSS attacks (tokens should NOT be stored here)
- ❌ Not suitable for large or critical data
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
- Dark mode or UI settings
- Tutorial completion flags
- Lightweight temporary state
✘ Bad Fit
- Images or large JSON objects
- Important user-generated data
- Long-term or permanent storage
- Authentication or security-sensitive info
Conclusion
- localStorage capacity is very limited (~5MB).
- Safari/iOS may delete it automatically.
- It is not safe for critical or large data.
- Use it only for lightweight, non-essential settings.
localStorage is convenient, but understanding its limitations is essential.
Think of it as a simple “memo pad,” not a long-term storage solution.
👉 https://tips.ojapp.app/en/scroll-seo-2/