User Feedback During Background Sync
You'll learn how to design UI patterns that communicate sync status to users, ensuring they understand when their actions are queued, actively syncing, or successfully completed.
Why User Feedback Matters
When using the Background Sync API, operations happen behind the scenes—sometimes long after the user has closed your app. Without proper feedback, users won't know if their form submission, photo upload, or message actually went through. They might retry unnecessarily or lose trust in your app.
Think of it like dropping a letter in a mailbox: you want confirmation it was accepted, notification when it's being delivered, and reassurance when it arrives.
UI Patterns for Sync Status
Queued State
When a user submits something while offline, immediately show that the action is saved and queued. Use visual cues like:
- A "Queued for sync" badge or icon
- Toast notifications: "Your message will be sent when you're online"
- List items marked with pending status
Syncing State
When the sync event fires and your service worker processes queued requests, update the UI to show active syncing:
- Spinner or progress indicator
- "Syncing now..." status text
- Animated icons to show work in progress
Completed State
After successful sync, provide clear confirmation:
- Success toast: "Message sent!"
- Remove queued badges
- Update item status to "completed"
- Consider sound or haptic feedback
Failed State
If sync ultimately fails (after retries), be honest:
- Error notification with actionable guidance
- "Retry" button for manual intervention
- Preserve the queued data so users don't lose work
Implementation Approach
Store sync state alongside your IndexedDB data. When the service worker updates request status, post messages to active clients so they can refresh the UI. Use the pattern of optimistic updates you learned earlier, combined with state tracking.
Key Takeaway: Transparent feedback about queued, syncing, and completed operations builds user trust and prevents confusion when background sync handles their actions invisibly.