-
Notifications
You must be signed in to change notification settings - Fork 115
Self Hosting the JavaScript Web SDK
Users should almost always use our CDN-hosted version.
In case of issues, we make the best effort to configure easy rollbacks in events of bugs. We host this file on Cloudflare's international CDN with a 2 or 3 days browser cache duration. OneSignal is used widely enough that many users will already have this file in their browser cache when they visit a new client's website. In cases where we plan to make an update to it in the near future, we will sometimes temporarily lower the browser caching duration so that the previous version is promptly expired much sooner.
Please update your SDK version regularly. From time to time, we add new features and bug fixes to our SDK. Releases more than a few weeks old may become incompatible.
- Web SDK releases are tagged by version (an incrementing integer) (e.g.
v120085
) - Browse tags online using GitHub or through the Git command line tool. When browsing online, select the latest tag and download the source
- The release should be available in
<repository root>/dist
- See the
README.md
file in<repository root>/dist
, and the instructions below
-
When referencing the OneSignal SDK on your webpages, replace:
<script src="https://cdn.onesignal.com/sdks/OneSignalSDK.js" async="async"></script>
with your own copy, e.g.:
<script src="https://yoursite.com/assets/OneSignalSDK.js" async="async"></script>
-
Modify both
OneSignalSDKWorker.js
andOneSignalSDKUpdaterWorker.js
identically, replacing:importScripts('https://cdn.onesignal.com/sdks/OneSignalSDK.js');
with your own copy. Any valid URL (a relative URL to your site, an absolute URL to a CDN) is fine here, e.g.:
importScripts('https://yoursite.com/assets/OneSignalSDK.js');
-
The files
OneSignalSDKWorker.js
andOneSignalSDKUpdaterWorker.js
should still:- Have the same file names
- Be accessible from the root of your site, and not a subfolder
If you'd like to move the worker file locations, please see Can the worker files be served from a subfolder of my site?.
-