Skip to content

Instantly share code, notes, and snippets.

@qwertypants
Created June 15, 2011 17:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save qwertypants/1027597 to your computer and use it in GitHub Desktop.
Save qwertypants/1027597 to your computer and use it in GitHub Desktop.
Super tiny JS loader
// {Boolean} c Condition
// {String} f File name
var loadjs = function(c,f) {
var l = f.length;
if ( c && f.substring(l - 3, l) === ".js") {
var j = document.createElement('script');
j.type = 'text/javascript';
j.src = f;
j.async = false;
if (typeof j != "undefined") {
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(j, s);
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment