A page that fetches its own data via JavaScript worked fine on the live production domain but failed to load anything on a staging subdomain.
Hardcoded Absolute URLs Break Cross-Origin Testing on Staging
Field Note #267
⚡ Quick Fix (TL;DR)
The Culprit: The script's fetch URL was hardcoded to the production domain rather than a relative path, making it a genuine cross-origin request once loaded from staging – confirmed directly via a CORS error in the browser console.
The Fix: Changing the hardcoded absolute URL to a relative path let the browser resolve it to whichever domain is actually serving the page – same-origin on both staging and production, no CORS involved on either. This is a strictly better pattern than the original, not just a staging workaround.
// Wrong — hardcoded absolute URL, breaks on any other domain:
var ERRORS_URL = 'https://staging.zu2b.com/zu2b-web-error-guide.json';
// Right — relative path, resolves to whichever domain serves the page:
var ERRORS_URL = '/zu2b-web-error-guide.json';
Rather not untangle this yourself? Our Done-For-You team handles exactly this kind of thing, start to finish.
See DFY options →
Was this helpful?
Thanks for the feedback!
Tagged in :