Web push requires background workers known as service workers to display notifications when your site isn't open. These background workers are regular JavaScript files that run in a special browser environment. The code in your site's OneSignalSDKWorker.js is the service worker.
Each subscriber's browser downloads the script from OneSignalSDKWorker.js to store a local copy for running, and checks for updates to the worker script by downloading OneSignalSDKWorker.js again periodically.
When:
- The user visits your site
- Or, the user receives a push notification
OneSignalSDKWorker.js will be downloaded from your site to check for updates, although this check only runs a maximum of once every 24 hours, to prevent too many requests to your site.
The periodic checks are required, and are performed by the browser, not by our SDK. The amount of time between checks cannot be greater than 24 hours.
With each subscriber's browser periodically checking for updates this way, it can lead to an increased traffic load.
Some ways to reduce your server's load are:
- Host resources elsewhere if possible
A common optimization is to serve your notification icon from an image host like Imgur instead of your site.
If your site's content is more static than dynamic, you can use CloudFlare to serve cached versions of your page and not just your assets, which can virtually eliminate requests to your server.
- Segmenting notification delivery
If none of these options are available, you may have to increase your server's performance to be able to handle the traffic requests.