Course contentsShow
← Web Development
Lesson 2430 of 2,98243. Service Workers Deep DiveFree lesson

Prompting Users for Updates

Build UI patterns to notify users when a new version is available and offer manual refresh.

Prompting Users for Updates

You'll learn how to build UI patterns that inform users when a new service worker version is ready and let them manually trigger a refresh.

The Core Idea

When your service worker updates (using skipWaiting or not), users might still be running the old version of your app. Rather than forcing an abrupt refresh, best practice is to show a polite notification that an update is available and give users control over when to apply it. This respects their current activity (they might be filling out a form!) while keeping your app fresh.

Think of it like a mobile app that shows "Update available" in the corner—non-intrusive but actionable.

How It Works

You've already learned about the controllerchange event and update lifecycle. Now you combine those with UI:

  1. Detect the update: Listen for the updatefound event on your service worker registration, and watch for the new worker entering the installed state while an old one is still active (meaning it's waiting).

  2. Show UI: Display a banner, toast, or button with a message like "New version available—Refresh to update."

  3. Handle user action: When clicked, call skipWaiting() on the waiting service worker (via postMessage), then reload the page when controllerchange fires.

This pattern gives users agency—they click when ready, and the update applies smoothly without losing unsaved work or interrupting their flow.

Key Takeaway: Prompting users for updates creates a respectful, user-controlled pattern that notifies them of new versions and lets them choose when to refresh, balancing freshness with uninterrupted experience.