Skip to content

Using Service Workers with PageBuilder Engine

PageBuilder Engine developers often want to adopt newer web platform features in their applications. This document covers Service Workers, which act as proxies between your apps and the external services they use.

PageBuilder Engine includes behavior designed to support serving service worker scripts. Service worker scripts kept in the resources directory of your PageBuilder Engine feature pack are automatically stored and served directly from S3, speeding up the delivery of those script assets.

Additionally, we’ve set up the server to simplify the work needed to pull down those service worker scripts. If a request is made for a .js file from the root domain without an outputType query param (for example, /sw.js), PageBuilder Engine can serve the file from resources/sw.js.

This behavior is not enabled by default. It requires a root-level JavaScript rewrite to be enabled by the Arc XP Delivery team. Until that rewrite is enabled, requests to /sw.js will return a 404.

For a service worker script located at resources/sw.js, you can install and register it using: navigator.serviceWorker.register('{deployment(/sw.js)}') (the deployment ID must still be appended) and it will automatically get pulled down from S3. Since all static resources are specific to a deployment, service worker scripts must also have a deploymentID param appended.

Verifying root-level JavaScript routing

You can check whether root-level JavaScript routing is enabled for a site in Arc Admin.

  1. Go to Arc Admin.
  2. Open the Delivery tile.
  3. Select the site you want to check.
  4. Open the site detail page.
  5. In the Additional properties section, look for ROOT_JS_REWRITE.
  • ROOT_JS_REWRITE = false means root-level routing is disabled. This is the default.
  • ROOT_JS_REWRITE = true means requests like /sw.js are rewritten to resources/sw.js.

If the property is false, contact Arc XP Customer Support to request it be enabled.