How to have different custom code for the same page in webflow staging
vs production
environment?
Different? Depends on what you’re trying to do I suppose, but that’s not the purpose of staging.
You can have your script look at the location host, check for webflow.io
and execute differently.
If you’re trying to separate dev, test, prod environments, I do this with a reverse proxy to inject different code in on the dev.mysite.com
version, which sources from staging.
Some docs here;
1 Like
Hey @pkongz you can use this code just change the url’s to your url’s and swap console logs wiht the code you want to run on each domain
// Define your staging and production domains
const stagingURL = "www.staging-domain.webflow.io";
const productionURL = "www.prod-domain.com";
// Check the current hostname and run environment-specific code
if (window.location.hostname === stagingURL) {
// Custom code for staging environment
console.log("Staging environment - Custom code for staging runs here.");
// Add any specific code for staging here
} else if (window.location.hostname === productionURL) {
// Custom code for production environment
console.log("Production environment - Custom code for production runs here.");
// Add any specific code for production here
} else {
console.log("Unrecognized environment.");
}