← Home ← Codex ← DEBT
Browse by Category
+ added · updated 7d
← Back to glossary

IndexedDB

javascript ES2015 Advanced
debt(d7/e5/b5/t7)
d7 Detectability Operational debt — how invisible misuse is to your safety net

Closest to 'only careful code review or runtime testing' (d7). Lighthouse can flag localStorage misuse for large data, but detecting IndexedDB quota errors, missing backend sync, or async blocking patterns requires runtime testing or manual inspection. Static detection is minimal; the common_mistakes (storage quota errors, missing sync) only surface under production load or deliberate offline testing.

e5 Effort Remediation debt — work required to fix once spotted

Closest to 'touches multiple files / significant refactor in one component' (e5). The quick_fix (migrate to idb library + add backend sync) is not a one-line swap—it requires refactoring the storage layer AND adding sync logic that may touch form handlers, API calls, and error handling across the component. If IndexedDB is already deeply integrated without sync, rewiring to treat it as cache and ensure PHP backend consistency touches multiple files.

b5 Burden Structural debt — long-term weight of choosing wrong

Closest to 'persistent productivity tax' (b5). IndexedDB choice affects all offline-capable features in a web app—any form, cached content fetch, or pending action must now consider IndexedDB state, quota limits, and sync timing. It's not load-bearing (you can work around it), but every data-persistence decision going forward must account for quota pressure, browser eviction, and backend sync strategy. This slows down multiple work streams that touch offline data.

t7 Trap Cognitive debt — how counter-intuitive correct behaviour is

Closest to 'serious trap' (t7). The core misconception—that IndexedDB is persistent like a server database—directly contradicts localStorage and contradicts how devs expect 'database' to behave. The canonical trap is that the browser can silently clear IndexedDB under storage pressure, making it unsafe as a source of truth. Developers accustomed to server DBs will assume data persists; the async-only API is also a secondary gotcha compared to the synchronous-looking localStorage they may have used before.

About DEBT scoring →

Also Known As

IndexedDB IDB browser database offline storage

TL;DR

Browser-native NoSQL database for offline-capable PHP web apps — stores structured data that survives page reloads, complements service workers.

Explanation

IndexedDB is a transactional object store persisted in the browser. Stores JS objects including Blobs. Indexed for efficient querying. Works offline (alongside Service Workers). Used for: offline drafts before sync to PHP, caching API responses, large client-side datasets. API is callback/promise-based (use idb library for cleaner async). Quota: typically hundreds of MB. Cleared by browser in storage pressure. Not accessible cross-origin.

Common Misconception

IndexedDB is persistent like a server database — the browser can clear it under storage pressure (low disk space); always sync critical data to your PHP backend and treat IndexedDB as a cache.

Why It Matters

PHP apps serving mobile users need offline capabilities — IndexedDB stores form drafts, cached content, and pending actions that sync to PHP when connectivity returns.

Common Mistakes

  • Not handling storage quota errors
  • Not syncing to PHP backend — treating IndexedDB as the source of truth
  • Using raw IndexedDB API instead of idb library
  • Blocking UI with synchronous-looking patterns (it's async)

Code Examples

✗ Vulnerable
// Raw API — verbose and error-prone:
const req = indexedDB.open('app', 1);
req.onupgradeneeded = e => e.target.result.createObjectStore('drafts');
req.onsuccess = e => {
    const db = e.target.result; // nested callbacks...
};
✓ Fixed
// idb library — clean async/await:
import { openDB } from 'idb';

const db = await openDB('app', 1, {
    upgrade(db) { db.createObjectStore('drafts', { keyPath: 'id' }); }
});

// Save draft locally:
await db.put('drafts', { id: 'post-1', content: editor.value, savedAt: Date.now() });

// Sync to PHP when online:
navigator.onLine && await fetch('/api/drafts', { method:'POST', body: JSON.stringify(draft) });

Added 17 Mar 2026
Edited 22 Mar 2026
Views 64
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
0 pings T 0 pings W 0 pings T 0 pings F 0 pings S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T 0 pings F 0 pings S 1 ping S 2 pings M 0 pings T 3 pings W 0 pings T 1 ping F 0 pings S 0 pings S 0 pings M 0 pings T 2 pings W 1 ping T 1 ping F 0 pings S 0 pings S 0 pings M 0 pings T 1 ping W
No pings yesterday
Google 10 Amazonbot 9 ChatGPT 6 Perplexity 4 Unknown AI 4 Ahrefs 3 SEMrush 3 Majestic 1 DuckDuckGo 1 Bing 1 Meta AI 1 Scrapy 1
crawler 39 crawler_json 3 pre-tracking 2
DEV INTEL Tools & Severity
🟡 Medium ⚙ Fix effort: High
⚡ Quick Fix
Use the idb library (wrapper) for clean async/await syntax; always sync critical data to PHP backend — IndexedDB can be cleared by the browser
📦 Applies To
javascript ES2015 web
🔗 Prerequisites
🔍 Detection Hints
localStorage used for large structured data that should use IndexedDB; no offline sync strategy for forms
Auto-detectable: ✗ No lighthouse
⚠ Related Problems
🤖 AI Agent
Confidence: Medium False Positives: Medium ✗ Manual fix Fix: Medium Context: File
CWE-312 CWE-922

✓ schema.org compliant