Skip to content

Instantly share code, notes, and snippets.

@philly-mac
Created July 30, 2012 09:53
Show Gist options
  • Save philly-mac/3205929 to your computer and use it in GitHub Desktop.
Save philly-mac/3205929 to your computer and use it in GitHub Desktop.
Load jQuery only if has not already been loaded
if (typeof jQuery == 'undefined') {
function getScript(url) {
var script = document.createElement('script');
script.src = url;
var head = document.getElementsByTagName('head')[0],
done = false;
// Attach handlers for all browsers
script.onload = script.onreadystatechange = function() {
if (!done && (!this.readyState || this.readyState == 'loaded' || this.readyState == 'complete')) {
done = true;
script.onload = script.onreadystatechange = null;
head.removeChild(script);
}
}
head.appendChild(script);
}
getScript("absolute_url_to_jquery.js");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment