Skip to content

Self Hosting the JavaScript Web SDK

Jason Pang edited this page Mar 24, 2017 · 16 revisions

Don't Host It Yourself If You Don't Need To

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.

Technical Instructions

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

HTTPS Web Push Integrations

  1. 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>
  2. Modify both OneSignalSDKWorker.js and OneSignalSDKUpdaterWorker.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');