Background Sync

The Background Sync API allows authorized Web applications to not rely on having stable internet connection and defer network-related operations to the moment the connection is available. The API is bound to the Service Worker, which is the code execution model that is separated from the owning Web application. This allows the Background Sync to operate also after the application window was closed.

The API itself is only a way of signaling the application about the restored connectivity. It might be used together with any Offline Storage solution to implement a data synchronization scheme or a replay mechanism for the network requests issued when the application was offline

The specification previously planned the second mode of operation - as a periodic sync, useful for automatic data synchronization from the internet - but this mode was dropped before it was implemented by any browser vendor.

As of December 2017, the API is only implemented in Google Chrome.

API glimpse

serviceWorkerRegistration.sync.register('syncTag')
Requests an one-off sync registration. Returns a Promise when the request has been registered.
self.addEventListener('sync', listener)
An event fired within the Service Worker instance when there is a connection available and the synchronization is possible. The listener is expected to call event.waitUntil(promise) specifying a Promise that resolves when the sync handling has been completed.

Resources