My website already has a service worker

Requirements

  1. Your existing service worker must be served from the root of your webserver or use the Service-Worker-Allowed header technique described in the Troubleshooting section.

Guide

1. Include the following inside your existing JavaScript service worker:

var fanplayrOptions = {
  version: 1,
  // When `true`, Fanplayr will add "install" and "activate" event handlers
  // to the Service Worker which will cause it to be installed and activated
  // immediately without waiting for any caches to load.
  // Set to `false` if your Service Worker implements either of these events.
  immediate: true
};
importScripts('https://static.fanplayr.com/client/sw.js?v=' + fanplayrOptions.version);

2. Include the following HTML on all pages of your website:

<script>
window.fanplayrServiceWorker = true;
</script>

Last updated