jemlifathi
jemlifathi

Reputation: 1582

Using PWA service workers to save/serve web service in offline mode

I have a vue.js/Cordova app in which I want data coming from Rest web services to be available in offline mode, the trivial solution first coming to my mind is using local storage API by indexing each w.s response and make my frontend service return data from local storage in offline mode or in case of a slow internet connection. But I think doing this directly using local storage API is very tricky, and I thought maybe using service workers and pwa concept can do the task properly. Now, my question is: in my use case, can service workers do the job? second, are service workers available in a Cordova android/iOS app ? Finally, what are probably the compatibility issues/usage risks when running on mobile devices ?

Upvotes: 1

Views: 472

Answers (1)

Jade Ellis
Jade Ellis

Reputation: 1542

Unfortunately, if you are using Cordova to serve up files from either file urls or http urls, as you probably will do unless serving from a website, it will not work on Android, due to the fact that service workers only work in secure contexts. See https://www.w3.org/TR/service-workers-1/#secure-context.

However, on iOS there is a plugin that allows you to use service workers, even on older versions that have no native support.

Even without the lack of support in android, service workers won't be present in enough platforms to be useful as a core part of your app.

In your case, as you are already using Vue, I recommend using Vuex, Vue’s Application Data Store. You also get some other benefits.

Upvotes: 2

Related Questions