Storing Complex Objects & Blobs in IndexedDB
Storing Complex Objects & Blobs in IndexedDB
One of the greatest capabilities of IndexedDB is its native support for the Structured Clone Algorithm. Unlike localStorage (which requires manual JSON.stringify that strips binary data and types), IndexedDB natively stores complex JavaScript objects—including Blob, File, ArrayBuffer, Date, Map, Set, and cyclic objects.
1. Supported Types vs. JSON Limitations
| Data Type | localStorage (via JSON) | IndexedDB (Structured Clone) |
|---|---|---|
| Binary Blobs & Files | Drops or requires huge base64 strings | Native binary storage (Zero overhead) |
| TypedArrays & ArrayBuffers | Loses typed structure | Supported natively |
| Date Objects | Converted to plain ISO string | Preserved as true Date instances |
| RegExp Objects | Lost / converted to empty object {} | Preserved |
| Circular Object References | Throws TypeError: Converting circular structure | Supported natively |
2. Storing & Retrieving Binary Images and PDF Blobs
In an offline PWA or multimedia app, you can download files via fetch(), store the raw binary Blob directly in IndexedDB, and render it offline without network access:
3. Rendering Stored Blobs in the DOM
To display a stored Blob without uploading or converting to base64, use URL.createObjectURL():
4. Storing Multi-Tier Relational Graphs
Because IndexedDB uses the Structured Clone Algorithm, complex hierarchical objects with circular relationships can be stored safely:
Practice Quiz
Cache API & Service Worker Storage
Continue learning with hands-on practice, examples, and exercises in the upcoming topic.
Related Lessons
| Previous Lesson | Next Lesson |
|---|---|
| IndexedDB Architecture & Transactions | Cache API & Service Worker Storage |
Practice Quiz
Test your understanding of this lesson with 5 questions. Each question has one correct answer.