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
As of early 2020, the API is only implemented in Chromium-based browsers.
The specification is complemented with Periodic Background Sync that allows requesting periodic events waking up the Service Worker, useful for automatic data synchronization scenarios.
- Requests an one-off sync registration. Returns a
Promisewhen the request has been registered.
- An event fired within the Service Worker instance when there is a connection available and the synchronization is possible. The
listeneris expected to call
Promisethat resolves when the sync handling has been completed.