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).
This component requires:
An active service worker with Workbox configured
Background Sync enabled in your PWA configuration
A broadcast channel configured for the queue
Background Sync automatically retries failed requests when the device regains connectivity. This component simply provides visibility and manual control over that process.
How It Works
Service Worker Queue: When requests fail, Workbox queues them in a background sync queue
Broadcast Channel: The service worker broadcasts queue status updates via a named channel
Component Listening: The BackgroundSync Queue component listens to the channel
Status Display: Component receives and displays the number of pending requests
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
The broadcast channel must be configured in both the PWA config file and the component. Mismatched channel names will prevent communication between the service worker and the component.
Handle Edge Cases
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
Always give users feedback when they trigger a manual replay. Even if the sync fails, users should know something happened.
Monitor Multiple Queues Separately
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
channelType: 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()
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
statusFired when a status update is received from the service worker containing the current queue state.
Event detail:
name(string): Name of the queueremaining(number): Number of pending requests in the queue
error
errorFired when an error occurs (e.g., no channel provided).
Event detail:
reason(string): Description of the error
How Queue Updates Work
The component automatically:
On Connect: Opens a BroadcastChannel connection with the specified channel name
Status Request: Immediately sends a
status-requestmessage to the service workerListen for Updates: Listens for status messages from the service worker
Dispatch Events: Emits
statusevents with queue informationOn 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-requestis receivedWhen a
replay-requestis processed
Related Components
BackgroundSync Form - Automatically queue form submissions when offline
Service Worker - Service worker configuration and setup
Connection Status - Monitor online/offline status
Sync Broadcast - Generic broadcast channel communication
Resources
Last updated
Was this helpful?