jwktje
jwktje

Reputation: 175

How to cache last loaded data on the client in Cordova app?

I'm building an app on Meteor and have been testing my app on my Android device. It works great. I'm publishing my data on the server and subscribing to it in the client.

But when I don't have data or the server is down, the mobile app shows no content. This makes sense as it can't load anything. But it must be possible to cache the last loaded data from the server so there is at least something to display in the mobile app when there is no connection.

I looked into appcache but that seems to be for assets as opposed to database content. Does anybody know how to make the Cordova version of a Meteor app cache the database locally so it will also work offline?

Upvotes: 1

Views: 191

Answers (1)

Wim Mostmans
Wim Mostmans

Reputation: 3601

To cache our iPad application configuration we use localStorage. It's super easy to use and really worked out well for use.

localStorage.settings = settings; // data from server

and when the application starts:

var settings = null;
if( navigator.network.connection.type === Connection.NONE ) {
   settings = localStorage.settings
} else {
   // fetch settings from server
}

We've been running this implementation for over a year now without any issues.

Upvotes: 1

Related Questions