Web data storage

In the browser itself you can save data in different ways. The main builtin approached are:

  • IndexedDB is the standard HTML5 database API. It works in newer browsers, but has some quirks on Safari, including all iDevices. There is an IndexedDBShim that runs on Safari and older browsers.
  • WebSQL is essentially for SQLite available in the browser, – this is non-standard, but the best storage api on Safari. Only works in Chrome and Safari.
  • LocalStorage is a simple synchronous key-value store with limited space.

Due to differences in platforms, and the IndexedDB API being a bit unusual.., there are different databases in JavaScript, that builds on top of IndexedDB/WebSQL:

  • PouchDB is CouchDB-like database for the browser. In my eyes this looks like the best bet for an in-browser database. It supports synchronisation of database to servers, multiple document versions, advanced queries. Also has a LevelUp(LevelDB and more) backend on node.js
  • LocalForage is a simple async key-value storage on top of IndexedDB, WebSQL, and LocalStorage. Good if you just need key/value storage.
  • LawnChair is a simple/tiny object storage, with various storage options. Was one of the best bet some years ago, but development is not that active anymore, and I would recommend LocalForage instead.
  • IDB-wrapper is a wrapper for IndexedDB that makes the API easier to use.
  • YDN-DB is a database on top of IndexedDB, WebSQL and LocalStorage, with queries, schemas etc. Uses google closure for building. If use case needs fulltext search, or indexes on top of LocalStorage, or is performance critical, this seems like a good bet.

Quick comparison of PouchDB and YDN

Flavour CouchDB, including replication IndexedDB, plus advanced features
Engineering node/browserify – more mainstream, easy development, also server-side support Google Closure – optimized, extra performance
Community Many developers, thriving open source community Several developers, though there seem to be only one main developer, that also offers commercial support.

IndexedDB performance hack: for raw performance key/value-storage, it is my experience that IndexedDB transactions slows things down. My workaround was to make a simple JavaScript key/value-storage wrapper on top of IndexedDB, that caches reads/writes in memory, and store changes to the database in bulks.