9

We're currently building a web app (Django, Ember), and we just found that most of our potential customers require sporadic offline access to the application.

What we need is not just "presenting" the app so user can navigate, caching stuff in the Manifest and so on (which I guess we will need eventually too), but we must let users actually operate as much as possible as if they were online. There will be obviously some features unavailable, but basic usage of the app should be available.

That said, I'd love to hear some thoughts on people that have confronted this scenario before. The way I see this, we need to:

1.- Either check if we're online / offline constantly or let the user specify when they're going offline (sort like Airplane mode in a smartphone).

2.- All data should be dumped into IndexedDB and from that moment on we use IndexedDB for anything related with data.

3.- When the user goes back online, a Synch process must try to dump the data from the offline user to the db online. While this might look dangerous, I don't expect a lot of users going offline at the same time while other online users are using the app, so I expect this synch process to don't become a real nightmare, also I don't expect to have race conditions.

Well, and there is obviously the option to create a Desktop standalone app...but I will try to avoid this as much as possible...

Thanks!

AlejandroVK
  • 6,905
  • 11
  • 43
  • 68

1 Answers1

4
  1. To check if the user is offline or online , you can use navigator.onLine but this property is not supported on all browsers. Then, if you target some of this browsers, you will have to implement an other solution with AJAX calls for example.

  2. Concerning the synchronisation, you can use available solution like CouchDB (NoSQL) on your server and use PouchDB (indexedDB) in your javascript front-end that will ease you the synchronisation process. If it doesn't meet your expectations, implement your own solution, to synchronize an indexedDB with your server database (MySQL, Postgres, MongoDB, etc...), of course, you can still use pouchDB on the front-end.

  3. Regarding performance, I think it will depend greatly on:

    • the number of servers that host your web applications
    • the number of replica of your master database
    • configuration of your servers (CPU and RAM)
Louis Barranqueiro
  • 8,594
  • 5
  • 35
  • 49
  • THanks for response, I've been reading a lot, looks like ServiceWorker-IndexedDB(PouchDB) and CouchDB seem the way to go. My only concern is how do I sync CouchDB (noSQL) with my PostgreSQL database in server... – AlejandroVK Nov 23 '15 at 11:49
  • PouchDB rather you mean no? because couchDB is the database on server. – Louis Barranqueiro Nov 23 '15 at 11:52
  • OH, you want to ue PouchDB with CouchDB and sync CouchDB with PostgreSQL. why not PouchDB and PostgreSQL directly? – Louis Barranqueiro Nov 23 '15 at 11:59
  • Not even sure if that can be done, I'm a total newbie in the offline-first world :D – AlejandroVK Nov 24 '15 at 08:26
  • It can be done but you have to implement the adapter. It a lot of works. Of course, the fatest way, is to use PouchDb with CouchDB. Check this [how to have complete offline functionality in a web app with postgresql database](http://stackoverflow.com/questions/19953256/how-to-have-complete-offline-functionality-in-a-web-app-with-postgresql-database) – Louis Barranqueiro Nov 25 '15 at 09:56