Skip to content

Instantly share code, notes, and snippets.

@learyjk
Created March 16, 2024 00:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save learyjk/0f4ea905af2bb7412d3718fd12974d9b to your computer and use it in GitHub Desktop.
Save learyjk/0f4ea905af2bb7412d3718fd12974d9b to your computer and use it in GitHub Desktop.
Staging vs. Production Code
const currentDomain = window.location.hostname;
let scriptElement = document.createElement('script');
scriptElement.type = 'text/javascript';
if (currentDomain === 'staging.webflow.io') {
// staging
scriptElement.src = 'http://127.0.0.1/index.js';
} else if (currentDomain === 'www.example.com') {
// production
scriptElement.src = 'https://cdn.jsdelivr.net/npm/@account-name-here/frontend-site@2.13.3/dist/location.js';
}
// Append the script element to the document head
document.head.appendChild(scriptElement);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment