Let’s see some workarounds to add web push notifications to a website if you cannot add a service worker to the root folder.
service-worker
How to change the scope of a service worker
The scope of a service worker defines when it is active and usually depends on the path where it is located. However in this tutorial we’ll see some directives that allow to change the default scope of a service worker, regardless of its location.
Web Push Notifications: Standard and Official Documentation
“Web Push Notifications” is a general term to refer to the push notifications sent by websites and web apps. However, if you are looking for an official document that defines the “Web Push Notifications” standard, you won’t find it. This is because this technology is made up of different technologies, each one serving to a specific purpose. Let’s find out what these technologies are and where the official standards are located (documentation).
How to add a service worker to WordPress
There are many reasons to add a service worker to WordPress: for example you may want to improve caching or add web push notifications. Let’s see how to do that.
Updating the service worker
Are you stuck with an old version of the service worker or your imported scripts are not being updated as you expect? This guide shows you how to ensure that your service worker and the imported scripts are updated in a timely manner.
Debugging service workers and push with Firefox
If you have problems with web push or with other service worker based technologies on Firefox, then you probably want to use the Firefox developer tools for debugging.
Update the Pushpad service worker to the latest version
In the last months we have rolled out new notification features and other performance improvements.
If you use Pushpad Pro, in order to receive the update, you should make a small change to your service worker.
Inspect service workers with Chrome
If you work with the Push API or service workers in general you know that debugging can be a pain. Fortunately Chrome has two hidden gems that can save you many headaches.
Update the service worker and the scripts imported with importScripts
If you change the Javascript code of a service worker, the browser may not apply the update immediately (as we have already discussed).
In order for the update to take effect you need to:
Service worker: importScripts never updates scripts
Pushpad is a service for web push notifications. In order to add push notifications to their websites, our customers need to install the service worker that we provide on their websites.
Initially we just asked customers to copy and paste the whole content of the service worker. However this meant that for every update we made to the script, our customers had to take action.
Then we discovered importScripts