Integration FAQ

What if I already have a Service Worker?

No problem. If you already have a Service Worker you can keep using it!

Just take the importScripts line from the Pushy Service Worker and paste it in to your existing Service Worker. The next time a user visits your site they will receive the updated Service Worker including the Pushly-specific code.

If you already have a Service Worker you'll likely need to follow the "Can I serve the Service Worker from a custom location?" question in this FAQ,

Can I serve the Service Worker from a custom location?

Yes, just add the sw property to the Pushly Javascript snippet with the value being the Service Worker's relative location to the public root of your site. For example, if your Service Worker is located at https://www.example.com/sw.js then the snippet should look like this:

var PushlySDK = window.PushlySDK || [];
function pushly() { PushlySDK.push(arguments) }
pushly('load', {
domainKey: 'DOMAIN_KEY',
sw: '/sw.js'
});

What if I can't serve the Service Worker from the public root of my site?

If you have to serve the Service Worker from a subdirectory of your site then an additional HTTP Response Header must be included when the file is served. This HTTP Header should look like the following:

Service-Worker-Allowed: /

This instructs the browser to allow the Service Worker to be scoped to the root directory rather than its default scoping of the directory it is in.