Script

Script (Exponea Service)

Description

The exponeaServiceWorker function manages the lifecycle of a service worker specifically for exponea (Exponea), a customer data platform used for marketing automation, event tracking, and web push notifications. It ensures that the correct version of the service worker (located under /static/) is actively registered, replacing any incorrect or outdated versions.

Purpose

  • Ensures consistency and correctness of the registered service worker.
  • Prevents service workers from interfering with exponea's tracking or notification functionality.
  • Helps manage deployment integrity by removing old or non-static service workers.

Feature Goal

  • Checks for Service Worker support:
    • Uses if ("serviceWorker" in navigator) to detect browser compatibility.
  • Retrieves current service worker registration:
    • Calls navigator.serviceWorker.getRegistration() to fetch any existing registration.
  • Validates existing service worker:
    • If a worker exists and is active, it checks:
      • Whether its script URL contains /static/.
      • If not, it's considered outdated or invalid.
  • Unregisters invalid worker:
    • Calls unregister() on the outdated service worker to remove it.
  • Registers the correct service worker:
    • If no worker exists or the previous one was removed, it registers:
      • "/static/service-worker.js" — the expected path for exponea’s scripts.

Use Case

  • Automatically invoked during application startup or exponea integration bootstrap.
  • Maintains clean and predictable service worker behavior.
  • Ensures push notifications and tracking run via correctly scoped scripts.

Copyright © 2026