Skip to content

Instantly share code, notes, and snippets.

@cnrudd
Last active August 29, 2015 14:04
Show Gist options
  • Save cnrudd/ac2c3572e7c4ebcd5c4d to your computer and use it in GitHub Desktop.
Save cnrudd/ac2c3572e7c4ebcd5c4d to your computer and use it in GitHub Desktop.
A little Javascript function that loads a javascript file only if a javascript object exists. Can be used to load JS files that depend on other JS files sequentially
function sequentialJSLoader(URL,conditionalObjName){
if( typeof conditionalObjName != "undefined"
&& eval('typeof ' + conditionalObjName) === "undefined"
){
// console.log(conditionalObjName + " not yet defined");
window.setTimeout(function(){sequentialJSLoader(URL,conditionalObjName);},500);
return;
}
var J = document.createElement("SCRIPT");
J.type = "text/javascript";
J.src = URL;
document.getElementsByTagName("HEAD")[0].appendChild(J);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment