How can Meteor apps work offline?

This is useful when:

  • the server is down and the client can't connect for real-time sync
  • there is no Internet connectivity
  • the user doesn't want to go online but wants to work with application;

Yes! This is already implemented in Meteor, for the most part.

If the connection to the server is lost, the client can still function locally. Database writes will appear to succeed on the client and reflect instantly on the screen. Once the connection is re-established Meteor will re-send all the pending method requests to the server and update the client display with the results from the server. This is all the result of latency compensation, being offline is treated like the server just being very slow.

Clients can monitor the reactive 'Meteor.status()' output to see the status of the current connection. For example you could use Meteor.status to drive a popup with a reconnect timer and a 'connect now' button, like gmail.

EDIT: of course, Meteor isn't magic. If you hit 'reload', or navigate away from the page, etc, while offline you'll lose your Meteor session and not being able to start again until you regain network. This is true of all web apps with offline mode, though, so it shouldn't come as a surprise to users of your app.


There's another couple of options that may solve the 'if your tab closes, or you reload' issue. I've not tried them yet but look interesting.

https://github.com/awwx/meteor-offline-data:

Meteor Offline Data

Home of the Meteor offline data project, implementing an "Offline Collection" which wraps a Meteor.Collection:

Data from the server is stored persistently in the browser database, making it available to the application even if the application starts up offline.

Changes made by the user are also saved in the browser database, preserving them if the browser is closed and reopened. The next time the application goes online the changes are sent up to the server.

Updates are reactively shared across browser windows open on the same application, even while offline.

and https://github.com/GroundMeteor/Meteor-GroundDB:

Features:

Light footprint

Broad browser support Chrome, Safari, Firefox and Internet Explorer 9 Fallback to normal Meteor.Collection if no localstorage Resume of changes in collections Resume of methods Works offline updating cross window tabs Support for SmartCollection Support for offline client-side only databases Uses EJSON.minify and EJSON.maxify to compress data in localstorage In the future there will be a customizable conflict handler on the server-side