BackgroundSync Queue

The BackgroundSync Queue component provides real-time monitoring and manual control of background synchronization queues in your Progressive Web App. When network requests fail (due to being offline or network errors), they are automatically queued by the service worker and retried when connectivity is restored. This component displays the number of pending requests and allows users to manually trigger queue replay.

This component is particularly useful for:

  • Showing users how many pending actions are waiting to sync

  • Providing manual retry buttons for failed operations

  • Building offline-first forms and data entry applications

  • Creating reliable e-commerce checkout flows that work offline

  • Implementing offline task management and todo applications

  • Monitoring background sync status in real-time

  • Giving users control over when to retry failed operations

  • Building dashboards that display sync status across multiple queues

Browser Support

The BackgroundSync Queue component relies on the Broadcast Channel API for communication with the service worker, which is widely supported in modern browsers.

Support level: Excellent - Works on all modern browsers that support service workers and the Broadcast Channel API (Chrome, Firefox, Safari 15.4+, Edge).

circle-info

This component requires:

  • An active service worker with Workbox configured

  • Background Sync enabled in your PWA configuration

  • A broadcast channel configured for the queue

circle-check

How It Works

  1. Service Worker Queue: When requests fail, Workbox queues them in a background sync queue

  2. Broadcast Channel: The service worker broadcasts queue status updates via a named channel

  3. Component Listening: The BackgroundSync Queue component listens to the channel

  4. Status Display: Component receives and displays the number of pending requests

  5. Manual Replay: Users can trigger immediate queue replay via a button action

Configuration

First, configure background sync with a broadcast channel in your PWA configuration:

The broadcast_channel name must match the channel parameter in your component.

Usage

Basic Queue Status Display

Visual Queue Status Indicator

Multiple Queue Monitoring

Automatic Polling for Status Updates

Integration with Form Submission

Best Practices

Always Configure Broadcast Channel

circle-exclamation

Handle Edge Cases

circle-info

Always check if the remaining value is an integer before displaying it. The initial value may be undefined until the first status update.

Provide User Feedback

circle-check

Monitor Multiple Queues Separately

circle-info

If your application has multiple background sync queues (forms, API calls, uploads), use separate component instances with different channel names for each queue.

Common Use Cases

1. Offline Form Submission Tracker

Track pending form submissions and show users what's waiting to sync:

2. E-Commerce Offline Checkout

Show customers their pending orders waiting to process:

3. Todo/Task Management Offline Sync

Display pending task changes waiting to sync with the server:

API Reference

Values

channel

Type: String Required: Yes

The name of the broadcast channel to listen to. Must match the broadcast_channel configured in your PWA configuration file.

Actions

replay()

Manually triggers replay of all pending requests in the queue. Sends a replay-request message to the service worker via the broadcast channel.

Targets

None

Events

status

Fired when a status update is received from the service worker containing the current queue state.

Event detail:

  • name (string): Name of the queue

  • remaining (number): Number of pending requests in the queue

error

Fired when an error occurs (e.g., no channel provided).

Event detail:

  • reason (string): Description of the error

How Queue Updates Work

The component automatically:

  1. On Connect: Opens a BroadcastChannel connection with the specified channel name

  2. Status Request: Immediately sends a status-request message to the service worker

  3. Listen for Updates: Listens for status messages from the service worker

  4. Dispatch Events: Emits status events with queue information

  5. On Disconnect: Closes the broadcast channel connection

The service worker broadcasts status updates:

  • When requests are added to the queue

  • When requests are successfully synced

  • When a status-request is received

  • When a replay-request is processed

Resources

Last updated

Was this helpful?