About service workers
Service workers are a great way to provide mobile-app-like features to websites. If you are not familiar with Service Workers, you can get acquainted here.
Web push notifications require the use of a service worker and WonderPush provides its own service worker.
Web applications can only have a single service worker. This guide explains how to integrate WonderPush when you already have your own service worker.
Step 1. Adapt your call to init
init
You can specify the URL of the service worker used by WonderPush when calling init
like this:
WonderPush.push(["init", {
webKey: "YOUR_WEBKEY",
serviceWorkerUrl: '/sw.js',
// … other initialization options
}]);
Please adapt the following in the above example:
/sw.js
should be adapted to the actual path to your existing service worker, relative to your domain name.
Step 2. Include our service worker in yours
In your existing service worker file, adapt YOUR_WEBKEY
and add the following code at the top:
importScripts('https://cdn.by.wonderpush.com/sdk/1.1/wonderpush-loader.min.js');
WonderPush = self.WonderPush || [];
WonderPush.push(['init', {
webKey: "YOUR_WEBKEY",
}]);
Please adapt the following in the above example:
YOUR_WEBKEY
should be replaced with your actual webkey.
Step 3. Test your integration
Try subscribing to push notifications and receive a push notification to test your integration. Remember we are here to help.
Updated about a year ago
What's Next
Web Push Notifications |
Website SDK |