Store user data in the browser so your web app continues to work offline without hitting the server
Cache API responses locally in IndexedDB using clean async/await syntax instead of tangled callback code
Read and write single values to the browser's local database with one-line shortcut methods without manually opening a transaction
IndexedDB transactions close automatically after the current JavaScript task, avoid mixing network calls inside a transaction.
The idb library is a small JavaScript wrapper around IndexedDB, a database built directly into web browsers. IndexedDB lets websites store data on a user's device so it can be accessed later, even without an internet connection. The native IndexedDB API uses an older style of handling results through event callbacks, which tends to produce tangled, hard-to-read code. This library replaces that style with promises, which is how modern JavaScript code handles operations that take a moment to complete. In practical terms, reading and writing to the local database looks much like any other modern JavaScript code. You can use the await keyword to wait for a result instead of wiring up callback functions. The library also adds shortcut methods for common one-off operations such as getting or putting a value, so you do not need to manually set up a transaction for each simple task. The file weighs about 1.19 kilobytes after compression, making it inexpensive to include on a web page. It can be installed as an npm package and imported in projects built with bundlers like webpack or Rollup, or loaded directly in the browser from a CDN address with no build step required. One important constraint described in the README: IndexedDB transactions close automatically once JavaScript finishes processing its current batch of work. If you make an unrelated network request in the middle of a transaction, the transaction may close before you are done, which causes an error. The library does not change this browser behavior, and the README includes an example showing exactly where the failure happens and why.
← jakearchibald on gitmyhub — every repo by this author, as a profile.
Verify against the repo before relying on details.