Skip to content

Instantly share code, notes, and snippets.

@fstamour
Created July 9, 2015 20:02
Show Gist options
  • Save fstamour/4f1617f2c6194241e420 to your computer and use it in GitHub Desktop.
Save fstamour/4f1617f2c6194241e420 to your computer and use it in GitHub Desktop.
function loadJS(src, retryP, delay) {
try {
var scriptTag = document.createElement('script');
scriptTag.type = 'text/javascript';
scriptTag.src = src;
var fail = function (event) {
console.error("Unable to load the script: '" + src + "'");
if (retryP) {
window.setTimeout(function () {
loadJS(src, retryP, delay);
}, (typeof delay == 'number') ? delay : 1);
}
}
scriptTag.addEventListener('error', fail, false);
var headTag = document.getElementsByTagName('head')[0];
headTag.appendChild(scriptTag);
} catch (e) {
console.error("An error occurred while trying to lunch the loading of the script: ", src);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment