- 05 Feb 2024
- 2 Minutes to read
Service Worker
- Updated on 05 Feb 2024
- 2 Minutes to read
Service Worker (SW) is a JavaScript command that can work even if the browser is not open. Thanks to this JS command, Insider can send web push notifications to users who have an active token regardless of being online. Insider's Push Service sends the push message to SW and the SW shows the notification to the user. Therefore, you must append Insider's SW to your website in order to send web push.
SW runs in the background even if there is no internet connection. It cannot reach the DOM. The website must support HTTPS in order to be able to use the SW. It listens to the push notification which comes from the server.
How to Integrate Service Worker and Requirements
You can integrate the Service Worker with three easy steps:
SSL Certificate
Since all pages using native opt-in must have HTTPS support, the website must have a valid SSL certificate.
Insider Tag Integration
You must integrate Insider Tag before integrating the Service Worker.
Insider Service Worker
The Insider Service Worker file is downloaded from Insider Website;
1. Follow this link. Right-click and Save As to download the Insider Service Worker file (insider/insider-sw-sdk.js). Upload the Insider Service Worker file to your domain subpath. Do not modify the name of the file or the content.
2. After uploading the SW file, the path is specified on Web Push Integration Settings if it is not in the root path.
3. After the integration, visit your website and click Allow button on the notification permission screen.
SW file should be registered on your browser. Open the devTools and check it from the “Application > Service Workers” tab. Status color should be green and the status note should be “activated and is running”. If its color is not green, you should check the SW integration since it is wrong.
4. After seeing the SW is registered successfully, you should visit other pages to check the registration status. While SW can work on a page, it might not work on another page if there is a mistake related with the integration. So, you should check other pages which are integrated. It should be green for the other ones, too.
How to Integrate Service Worker to Accelerated Mobile Pages (AMP)
If you want to integrate the SW to Accelerated Mobile Pages (AMP), you should apply 4 more steps. After completing them in the following page, you can test it.
After integrating the AMP, you should visit your website on the mobile view. You will see a button to subscribe when you visit the page on which the integration is applied. Then, you should click the button and subscribe to the mobile site.