Bjorn Pijpops
Bjorn Pijpops

Reputation: 373

Angular PWA adding background sync without WorkBox

So my question is simple:

Is there background sync when using Angular PWA. For certain reasons, I cannot use WorkBox.

The only info I have found is: https://github.com/angular/angular/issues/22145

Which is currently still open. Are there any alternatives?

I feel like without background sync, making an 'offline app' is impossible. I have found this https://golb.hplar.ch/2018/12/background-sync-ng.html which tells me there is a method unfortunatly I don't have that much experience with PWA in general and I don't get how the above link works/can help me.

Any guides or solutions are welcome!

Upvotes: 2

Views: 4326

Answers (2)

Ian
Ian

Reputation: 3149

@angular/service-worker does not have Background Sync API support.

The feature request is tracked here

Angular PWA library re-builds the service worker based on the ngsw-config.json file. It is not recommended to modify this generated service worker as it gets rebuilt upon build, so therefore you're at the mercy of the library vendor, which doesn't yet have support for the background sync API.

Upvotes: 2

Chris Love
Chris Love

Reputation: 3893

First, separate Angular out of this problem, it has nothing to do with the service worker. Totally separate animals.

Workbox is just a library that abstracts a lot of the service worker caching patterns into a more manageable API and adds background sync when it is supported by the browser.

You can do use the background sync API without Workbox. I will warn you it is a very complex API, just like IndexedDB is.

You do not need background sync to make a PWA work offline. It is completely optional. In fact, because only Chrome and Edge support background sync I don't even bother with the API. Instead, if I need offline sync capabilities I build a solution based on the application needs. I use a combination of IndexedDB and Service Worker cache to persist data.

The advantage the background sync API gives you is it will fire the service worker up without the user active in the application or even the device. Just when the device feels the network is available again.

Upvotes: 2

Related Questions