PWA & Custom Service Worker Filename

we will switch our website to full PWA with its own cache handler and other functionalities. However, we still want to use webpushr for push messages. Unfortunately the documentation doesn’t provide any information about setting things up with an existing service worker.

We’ll be using Google (https://developers.google.com/web/tools/workbox). We won’t use any special features, just some Cache-Handlers.

In order to get it work, I imported the script in our service-worker and added a second param to webpushr.init (within webpage):

if ('serviceWorker' in navigator) {
  navigator.serviceWorker.register('/custom.sw.js');

  ... webpushr standard script goes here

  webpushr('init', 'long-gibberish-key-here', '/custom.sw.js');
}

Don’t know, if it will register twice now or if we have to implement it in another way, so thanks for any hints.

Your approach will work. You can certainly pass the service worker filepath & filename as a parameter. The only thing to keep in mind is that the Service Worker file path should be the root directory for the domain.

Please also remember to add the following to the new service worker file: importScripts('https://cdn.webpushr.com/sw-server.min.js');