IndexedDB is a full NoSQL database in the browser. At Google, we use it for offline-first applications and caching large datasets.
Why IndexedDB?
| Storage | Capacity | Sync/Async | Data Type |
|---|---|---|---|
| localStorage | 5MB | Synchronous | Strings only |
| sessionStorage | 5MB | Synchronous | Strings only |
| IndexedDB | GBs | Asynchronous | Any structured data |
Basic Operations with idb Library
Transactions
Offline-First Pattern
Best Practices
- Always use a wrapper library like
idb— the raw API is callback-based and painful - Version your schema and handle upgrades carefully
- Use indexes for any field you query by
- Keep transactions short — they auto-commit when idle
- Handle QuotaExceededError gracefully