Periodic Sync

The Periodic Sync component enables your Progressive Web App to synchronize data in the background at regular intervals, even when the app is closed. This feature leverages the Periodic Background Sync API to keep content fresh without requiring constant user interaction.

Introduction

Periodic Background Sync allows your PWA to:

  • Fetch fresh content at regular intervals in the background

  • Update local caches with the latest data

  • Synchronize data when the device is idle and on Wi-Fi

  • Provide up-to-date content when users return to the app

  • Reduce data usage by syncing only when conditions are optimal

circle-info

Periodic Sync requires an active service worker and is subject to browser-controlled intervals. The browser decides when to actually trigger syncs based on site engagement and device conditions.

Browser Support

Browser
Desktop
Mobile

Chrome/Edge

✅ 80+

✅ 80+

Firefox

❌ Not supported

❌ Not supported

Safari

❌ Not supported

❌ Not supported

Opera

✅ Full

✅ Full

Samsung Internet

N/A

✅ 13+

circle-exclamation

Prerequisites

Before using Periodic Sync, ensure that:

  1. Service Worker is enabled in your PWA configuration

  2. Workbox is enabled as it provides the necessary helpers

  3. The user has granted the periodic-background-sync permission

Usage

Basic Periodic Sync Registration

First, import the helpers in your JavaScript:

News Feed Synchronization

Weather Data Synchronization

Social Media Timeline Sync

Podcast Episode Download

Best Practices

1. Request Minimal Sync Intervals

The minInterval parameter is a suggestion, not a guarantee. The browser may sync less frequently based on:

  • Site engagement (how often user visits)

  • Device battery level

  • Network connectivity (prefers Wi-Fi)

  • Data saver mode

2. Check Permission Status

Always check if the periodic-background-sync permission is granted:

3. Handle Sync Failures Gracefully

Background syncs can fail for various reasons:

4. Respect User Data Preferences

Only sync essential data automatically. For large downloads, ask for user permission:

5. Provide User Control

Let users manage sync settings:

Common Use Cases

1. News and Content Aggregation

Keep news feeds fresh with periodic updates:

2. Inventory and Pricing Updates

For e-commerce apps, keep product information current:

3. Calendar and Event Synchronization

Keep calendar events synchronized:

API Reference

Client-Side Helpers

registerPeriodicSync(tag, minInterval, options)

Registers a periodic background sync task with the service worker.

Parameters:

  • tag (String, required): Unique identifier for this sync task

  • minInterval (Number, required): Minimum interval in milliseconds between syncs

  • options (Object, optional): Additional registration options

Returns: Promise<void>

Example:

Notes:

  • Requires the periodic-background-sync permission

  • The browser controls actual sync frequency based on user engagement

  • Only works when the service worker is active

onPeriodicSync(tag, callback)

Listens for periodic sync completion events from the service worker.

Parameters:

  • tag (String, required): The sync tag to listen for

  • callback (Function, required): Function called when sync completes. Receives sync data as parameter.

Returns: void

Example:

Event Data Structure:

Service Worker Functions

registerPeriodicSyncTask(tag, callback, priority)

Registers a task to be executed when a periodic sync event occurs in the service worker.

Parameters:

  • tag (String, required): Unique identifier matching the client-side registration

  • callback (Function, required): Async function to execute during sync. Receives the event object.

  • priority (Number, optional): Execution priority (lower numbers run first). Default: 100

Returns: void

Example:

notifyPeriodicSyncClients(tag, payload)

Sends a message to all clients listening for a specific periodic sync event.

Parameters:

  • tag (String, required): The sync tag

  • payload (Object, optional): Custom data to send to clients

Returns: void

Example:

The payload will be merged with default properties:

Unregistering Periodic Sync

To stop a periodic sync:

Checking Registered Syncs

List all registered periodic syncs:

Additional Resources

Last updated

Was this helpful?