Periodic Sync
The Periodic Background Sync API allows your PWA to fetch fresh content periodically in the background, even when the app is closed. This ensures users always have up-to-date data when they open your app.
Overview
Periodic sync enables:
Background updates: Fetch fresh content while app is closed
Improved UX: Users see latest content immediately
Reduced data usage: Sync only when on WiFi/charging
Battery efficiency: Browser controls execution based on engagement
How It Works
Client registration: App requests periodic sync with a tag and interval
Browser scheduling: Browser decides when to actually run sync (based on engagement, battery, etc.)
Service worker execution: Service worker performs background task
Client notification: Service worker notifies clients of updates
Browser Support
Service Worker Implementation
Basic Task Registration
Create periodic tasks in your service worker:
Helper Functions Reference
The bundle generates the following helper functions in the service worker:
registerPeriodicSyncTask(tag, callback, priority)
Register a callback for a periodic sync tag. Optional priority (default: 100) controls execution order.
notifyPeriodicSyncClients(tag, payload)
Send a message to all clients via BroadcastChannel when sync completes.
openCache(name)
Open (or reuse) a named cache instance.
Multiple Tasks Under Same Tag
Register multiple related tasks with priorities:
Complete Example: Blog Post Sync
Client-Side Registration
Basic Registration
Request periodic sync from your application:
Listening for Sync Updates
Receive notifications when sync completes via BroadcastChannel:
Common Use Cases
News/Content Updates
User Data Prefetch
Browser Execution Control
Factors Affecting Execution
Site Engagement Score: High engagement = more frequent sync
PWA Installation: Installed PWAs get higher priority
Device State: Battery level, charging status, data saver mode
Network: WiFi preferred over cellular
Interval Duration: Very short intervals (< 12 hours) often ignored
Recommended Intervals
Managing Periodic Sync
Check Registered Tags
Unregister Periodic Sync
Testing
Force Sync in DevTools
Open DevTools (F12)
Go to Application → Service Workers
Find your service worker
Look for "Periodic Sync" section
Enter tag name and click "Start"
Graceful Degradation
Handle unsupported browsers:
Limitations
Supported: Chrome, Edge (Chromium-based) only
Not Supported: Safari, Firefox, older browsers
Platform: Android and Desktop only (not iOS)
Limited execution time (typically < 30 seconds)
Browser decides actual execution time
Permissions
Best Practices
Use reasonable intervals: 12+ hours recommended
Minimize network requests: Batch operations into a single sync
Provide user control: Allow users to configure sync frequency
Handle failures gracefully: Return Promises, use try/catch
Check network conditions: Skip heavy sync on poor connections
Related Documentation
Background Sync - One-time background sync
Service Worker Configuration - Service worker setup
Workbox - Workbox features
Last updated
Was this helpful?