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

The updatefound Event

Detecting when a new service worker is found and installing using the updatefound event.

The updatefound Event

You'll learn how to detect when a new service worker version is discovered and begins installing.

What Is the updatefound Event?

When your browser checks for service worker updates (automatically every 24 hours, on navigation, or manually), it compares the new service worker file against the currently installed one byte-by-byte. If they differ, the new service worker enters the Installing state. At this exact moment, the service worker registration fires an updatefound event.

Think of it like a package tracking notification: the moment your delivery service detects a new package is on its way, you get an alert—even though it hasn't arrived yet. The updatefound event is that alert for your web app.

Why This Matters

The updatefound event gives you the earliest possible notice that an update is coming. This is your opportunity to:

  • Show users a "New version available" banner
  • Monitor the new service worker's installation progress
  • Prepare your UI for a potential refresh prompt

Listening for updatefound

You listen for this event on the service worker registration object:

navigator.serviceWorker.register('/sw.js').then(registration => {
  registration.addEventListener('updatefound', () => {
    const newWorker = registration.installing;
    console.log('New service worker found and installing!');
    
    // The newWorker is now in the Installing state
    // You can monitor its state changes from here
  });
});

The updatefound event fires once per update discovery. When it fires, registration.installing points to the new service worker instance that's currently installing.

Key Takeaway: The updatefound event is your first signal that a service worker update has been detected and installation has begun, letting you notify users and track the update lifecycle proactively.