Steps on self-hosting and setting up the JavaScript SDK in your CDN.
2 minute read
RudderStack recommends serving the JavaScript SDK on your own domain over self-hosting it, especially to defend against the adblockers.
Self-hosting the SDK is only recommended in cases where you want to create a zero-gap architecture and ensure no data goes out to any external service.
This guide walks you through the steps for self-hosting the RudderStack JavaScript SDK.
Prerequisites
For self-hosting the JavaScript SDK, RudderStack recommends following the below directory structure (as present in RudderStack’s CDN) to place the SDK and the associated files:
In this structure, there are two directories - modern and legacy - present in the base directory.
The SDK bundle in the modern directory is built for ES2015, while the legacy bundle is for ES5, with all the plugins bundled into the core SDK.
Place the files and folders listed in the below table within these directories:
File/folder name
Description
rsa.min.js
The core SDK file.
js-integrations
Directory for storing the device mode destination SDKs.
plugins
Directory for storing the plugins. Note that this is applicable only for the modern folder.
Setup
RudderStack recommends downloading and hosting all the device mode destination SDKs, plugins, and source map files to help with troubleshooting.
Use the below links to download the required device mode destination SDK file with the corresponding source map file from the RudderStack CDN (https://cdn.rudderlabs.com/). Then, place the downloaded files in the js-integrations folder of the modern/legacy bundle, as applicable.
(Only applicable for the modern bundle) Download the plugin files with the corresponding map files from the RudderStack CDN and place them in the plugins folder.
If your JavaScript SDK file name is notrsa.min.js, then update sdkName in the loading snippet to:
varsdkName="<custom-file-name>.min.js";
Load device mode destinations and plugins
If you’ve installed the SDK via CDN and have retained the recommended directory and file structure, the SDK automatically determines the location of the device mode destinations and plugins.
Otherwise, provide location of the destination SDKs via the destSDKBaseURLload API option:
This site uses cookies to improve your experience while you navigate through the website. Out of
these
cookies, the cookies that are categorized as necessary are stored on your browser as they are as
essential
for the working of basic functionalities of the website. We also use third-party cookies that
help
us
analyze and understand how you use this website. These cookies will be stored in your browser
only
with
your
consent. You also have the option to opt-out of these cookies. But opting out of some of these
cookies
may
have an effect on your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. This
category only includes cookies that ensures basic functionalities and security
features of the website. These cookies do not store any personal information.
This site uses cookies to improve your experience. If you want to
learn more about cookies and why we use them, visit our cookie
policy. We'll assume you're ok with this, but you can opt-out if you wish Cookie Settings.