2

Does Meteor-JS support offline storage/cache?

From what I'm reading: https://guide.meteor.com/collections.html :

Instead, on the client, a collection is a client side cache of the database. This is achieved thanks to the Minimongo library—an in-memory, all JS, implementation of the MongoDB API.

The in-memory part seems to negate working offline. Am I wrong?

EDIT: By "offline" I mean as many as possible of those qualities:

  • load the app even without internet connection, showing user's data
  • make edits offline, sync them later, even if offline for e.g. hours
  • when loading the app while offline, the not-yet-synced edits should also show up

EDIT2: I guess the proper term would be offline-first

KarolDepka
  • 8,318
  • 10
  • 45
  • 58

2 Answers2

1

This feature doesn't come out of the box. Even if you make changes to the client, they will be reflected in the client but once the connection to the server is established, the server data will I override the changes.

You will have to manually push the data. One way of doing this is using local storage of the browser. You can save the data in local storage and push it in the server once connection is established to make the changes 'permanent'.

As pointed out in comments: Meteor will try to keep calling the method, till the connection is re-established is using Meteor.call, but once the tab is closed the data in the client will be lost. So, ensure the data survives closing of tab, store it in local storage.

Ankit
  • 1,118
  • 13
  • 21
  • If changes are made through a `Meteor.call`, indeed they will be reflected in the client (optimistic UI), but actually the client will also [keep on trying](https://guide.meteor.com/methods.html#retries) to send the method call to the server, until it succeeds or the app is closed (and taken out of memory on a device with Cordova). – ghybs Aug 28 '16 at 03:44
  • It will stop trying, when the user closed the tab and the data to be entered will be lost. – Ankit Aug 29 '16 at 05:07
  • OP's point sounds to be more on hybrid app, not accessed through browser. The hybrid app goes out of the device memory much less often than a browser tab. – ghybs Aug 29 '16 at 05:42
  • Okay! Thanks for the pointer. I will read more on this. Thanks! – Ankit Aug 29 '16 at 05:48
1

You are right about having concerns about the "in-memory" part of Minimongo. But on an offline device this is not as bad as it can look like: as long as the app is kept in memory (i.e. sitting in a tab if opened through a browser, or not forcedly closed if opened as a Cordova packaged app), your Minimongo lives and retains your data.

However, should the browser tab be closed, or the Cordova app brought out of device memory (i.e. user forces it to close through the task switcher / apps manager, or Android is getting short of RAM and looks for unused apps to close. This also means that just going back to home screen keeps your app in memory), then your Minimongo (and its data) goes away.

But there are packages that can take care of that use case as well. See How can Meteor apps work offline?

Graham
  • 7,431
  • 18
  • 59
  • 84
ghybs
  • 47,565
  • 6
  • 74
  • 99