Steps on self-hosting and setting up the JavaScript SDK in your CDN.
4 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: Directory structure
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 - v3 and 3.x.y (denoting the specific SDK version) - within the base directory.
Folder name
Description
v3
Contains the core SDK files - rsa.min.js and rsa.min.js.map.
3.x.y
Contains the device mode integrations and plugins.
Each of the above folders folders has two subdirectories - modern and legacy.
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.
The modern folder within 3.x.y further contains the following subdirectories:
Folder name
Description
js-integrations
Directory for storing the device mode destination SDKs.
plugins
Directory for storing the plugins.
Setup
RudderStack recommends downloading and hosting all the device mode destination SDKs, plugins, and source map files to help with troubleshooting.
Then, place these files in the v3 > modern / legacy folder within your base directory, as applicable.
2. Download device mode integrations
Download the required device mode destination SDK files along with the corresponding source map file from the RudderStack CDN (https://cdn.rudderlabs.com/) using the below URL:
Note that the SDK loading snippet automatically appends /v3/ to the sdkBaseUrl path in accordance with the recommended directory structure.
If you have placed the core SDK files in a structure that is different to the recommended directory structure, make sure to update the sdkVersion variable in the snippet accordingly.
For example, if your modern folder is placed within a subdirectory called custom-version-id instead of v3, then your updated SDK loading snippet should look like:
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.