Replace/Switch dev-local / production JavaScript on debug ?
Here is a little JavaScript, at HTML page load, to switch between prod and dev/debug JavaScript files.
The script checks parts of current URL to define whether production or development context is on.
Then it calls loadJS function, to load targeted JavaScript files and, optionally, calls back a function in the new JavaScript file once it is loaded.
<script type="text/javascript">
// LOADING FUNCTION
function loadJS(url, fnt)
{
var script = document.createElement(‘script’);
script.src = url;
if (typeof fnt !== ‘undefined’) { script.onload = function () {
fnt;
};}
document.head.appendChild(script);
}
// SWITCHER DISTANT / LOCAL
if (window.location.host.indexOf(‘localhost’) > -1)
{
loadJS(« http://localhost/…/wp_config.js »);
loadJS(« http://localhost/…/wp_utils.js », start);
}
else if (window.location.host.indexOf(‘MyDomainName’) > -1)
{
loadJS(« http://www.MyDomainName.fr/…/wp_config.js »);
loadJS(« http://www.MyDomainName.fr/…/wp_utils.js », start);
}
</script>