Working OFFLINE

Hey all, I’ve got a client who has sales reps out in rural country areas, wifi / data may not pick them up.

So, Meteor would allow me to create a mobile version of the app, which would still work, right? As long as they sign in to the app from wifi at the office, their account should work in the field?

They need to take photos of properties and push that to the server – but what if they’re offline?

Any cool plugins or concepts to help figure this out?

I’m not sure if something off the shelf exists. I ended up making offline work with the following:

  • Application tier assets (css/js bundles, other images) using the appcache package
  • Images cached using the regular image cache (this is not optimal, but I didn’t want to use up HTML5 storage space)
  • Data cached for offline with Ground DB. That lib has a way to automatically cache documents from a publication, but I went a more manually route and pull my documents over a Meteor method, then populate the Ground DB instance. In many cases I could probably have just used localforage directly, since I don’t really need the entire MiniMongo query engine. Since I enabled authoring/editing, I had to work out a syncing strategy, to make sure when I published the locally edited documents, they get updated on the remote. There are collision issues to be careful about with that.
  • An alternative to GroundDB could be to put the documents all into redux, and using some offline redux middleware. I have been moving away from redux for anything other than pure state, for a number of reason - mostly I just find other patterns (like direct meteor data containers) easier to manage.

In the future I’ll probably migrate the images and app tier assets to a service worker implementing the Cache API. But this solution works today.

For image uploads, you’ll probably have to create some kind of local queue (maybe stuff the images into a GroundDB collection or localforage) when you are offline, and upload as soon as a connection is detected.

Thanks, that’s kind of what I was thinking. I’ve used GroundDB before, works great.

So yeah, if I cache the local object, then push it from the que with the data, it should work.

My concern would be login / authentications from a remote location. Maybe I’ll create a hash key, save to local storage, and that will over-ride. So login once and boom, done.

Thanks for the reply, friend.

I haven’t done extensive testing with the login state and offline, but it does seem to work. I think the Meteor account system uses a token in Local Storage, pretty much the way you have described already. Inspecting that in dev tools, it looks like it has a 3 month expiration time.

Nice.

I just spoke to my client, and looks like we will be proceeding with this app!

HERE WEEEE GOOO