Skip to content

Instantly share code, notes, and snippets.

@makbeta
Created June 12, 2013 22:33
Show Gist options
  • Save makbeta/5769721 to your computer and use it in GitHub Desktop.
Save makbeta/5769721 to your computer and use it in GitHub Desktop.
JS: Add/execute Scripts after jQuery is asynchronosly loaded
function addScriptsWhenJQueryIsLoaded(myScripts) {
var numScripts = myScripts.length;
if (window.jQuery){
//possibly some other JQuery checks to make sure that everything is loaded here
console.log('Debug: jQuery loaded, loading scripts, number of script is '+numScripts);
window.$ = jQuery.noConflict();
var $anchor = jQuery('#overlay');
if(numScripts > 0) {
for(var i=0; i < numScripts; i++) {
var $newScript = jQuery('<script>').attr('type', 'text/javascript').attr('src', myCloScripts[i]);
console.log($newScript);
$anchor.after($newScript);
}
}
} else {
setTimeout(function() { addScriptsWhenJQueryIsLoaded(myScripts); }, 500);
}
}
var myScripts = new Array();
myScripts.push("/js/scripts.js");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment