Skip to content

Instantly share code, notes, and snippets.

@dannypule
Created January 6, 2017 13:15
Show Gist options
  • Save dannypule/299a11cc793eb9f5041da7ff947957a6 to your computer and use it in GitHub Desktop.
Save dannypule/299a11cc793eb9f5041da7ff947957a6 to your computer and use it in GitHub Desktop.
<script>
console.log('APP_ENVIRONMENT: ' + APP_ENVIRONMENT);
switch (APP_ENVIRONMENT) {
case 'DEVELOPMENT':
document.getElementById("polyfills_js").src = 'http://localhost:8085/polyfills.js';
var vendorJsInterval = setInterval(function () {
if (window.POLYFILLS_JS_LOADED) {
document.getElementById("vendor_js").src = 'http://localhost:8085/vendor.js';
clearInterval(vendorJsInterval);
}
}, 50);
var appJsInterval = setInterval(function () {
if (window.POLYFILLS_JS_LOADED && window.VENDOR_JS_LOADED) {
document.getElementById("app_js").src = 'http://localhost:8085/app.js';
clearInterval(appJsInterval);
}
}, 50);
break;
case 'TEST':
case 'STAGING':
case 'PRODUCTION':
var oReq = new XMLHttpRequest();
oReq.onload = reqListener;
oReq.open("get", "../../Scripts/webapp/dist/assets.json?_" + new Date().getTime(), true); // prevent caching with new Date().getTime()
oReq.send();
function reqListener(e) {
var assets = JSON.parse(this.responseText);
var BASE_URL = './Scripts/webapp/dist/';
document.getElementById("polyfills_js").src = BASE_URL + assets.polyfills.js;
var vendorJsInterval = setInterval(function () {
if (window.POLYFILLS_JS_LOADED) {
document.getElementById("vendor_js").src = BASE_URL + assets.vendor.js;
clearInterval(vendorJsInterval);
}
}, 50);
var appJsInterval = setInterval(function () {
console.log('interval');
if (window.VENDOR_JS_LOADED && window.POLYFILLS_JS_LOADED) {
document.getElementById("app_js").src = BASE_URL + assets.app.js;
clearInterval(appJsInterval);
}
}, 50);
}
break;
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment