Background Sync APIs
The Web Background Sync APIs enable web apps to defer actions, such as sending data to a server or fetching fresh content in the background.
1. Background Sync
Background Sync is designed to ensure critical actions (like sending a message, uploading a photo, or submitting a form) complete successfully even if the user has poor or no internet connection. When an application registers a "one-off" sync event, the browser queues the task and waits for a stable connection. Once the network is available (even if the user has since closed the tab or the browser), the browser wakes up the Service Worker to execute the task, ensuring that user data isn't lost due to connectivity issues.
2. Periodic Background Sync
Periodic Background Sync serves a different purpose: it is an opportunistic tool used to keep an application's content fresh by fetching data in the background at intervals determined by the browser. Unlike a standard timer, the browser decides when to wake the Service Worker based on factors like battery life, network status, and how frequently the user engages with the app. This is typically used for "read-only" flows, such as downloading the latest news articles or refreshing a weather dashboard, so that when the user eventually opens the app, the content is already there and waiting without a loading spinner.
API
Code
Ready to generate your PWA?
Try our PWA toolkit free of charge and without limits for 14 days. No credit card required.
Generate PWA See plans