Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PouchDB preload database

Sorry is this is a silly question, then I am drowning in a glass of water (not rare BTW). Is there any way to setup a web (ideally cordova) application with a preloaded (ready to use) PouchDB database(s)? Ideally what I'd want is having a PouchDB database(s) file(s) ready to use when doing db = new PouchDB('databaseName') without having to load all documents at the very first time the app is run.

I know there is the pouchdb-replication-stream but I'd need the dump file to load and then the size of the application data would be duplicated (both in the dump file and then the PouchDB database(s)). Also no chance for remote loading.

Cheers!!

like image 475
Sarasti Avatar asked Feb 18 '26 18:02

Sarasti


1 Answers

Edit: you can now preload a SQLite database or use pouchdb-load; there are instructions in this blog post.

Currently the only way to completely preload is to use the SQLite Plugin, then have a build step where you use PhantomJS and copy the SQLite files into your app.

I don't generally recommend the SQLite Plugin due to 1) general instability of implementation and 2) slowness compared to IndexedDB/WebSQL. So if I were writing such an app and I wanted the best possible preload performance, I would:

  1. Use pouchdb-dump-cli to dump to a file
  2. Load using pouchdb-load into a PouchDB, throw up a spinner on initial load while the app is loading if you really need to.

Some optimizations you could do here:

  1. The worker-pouch plugin works on Android (not iOS sadly), and can be used to avoid blocking DOM operations. Should work with the pouchdb-load plugin, or you can just do everything inside of a worker (better to avoid any blocking, not just IndexedDB-related blocking).
  2. To avoid blocking the user during initial load, break up your dump file into some subset of critical data, load that first and then load the rest of the data afterwards.
like image 141
nlawson Avatar answered Feb 21 '26 14:02

nlawson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!