Created
September 19, 2011 17:00
-
-
Save jonahlyn/1226954 to your computer and use it in GitHub Desktop.
Load jQuery only if it hasn't already been included somewhere on the page.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Load jQuery only if needed */ | |
(function(){ | |
var scriptAdded = false, js; | |
function initJQuery() { | |
if(typeof(jQuery) === 'undefined'){ | |
if(!scriptAdded){ | |
js = document.createElement('script'); | |
js.src = 'https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js'; | |
var first = document.getElementsByTagName('script')[0]; | |
first.parentNode.insertBefore(js, first); | |
scriptAdded = true; | |
} | |
setTimeout(initJQuery, 50); | |
} else { | |
// Do what you need to do with jQuery here. | |
} | |
} | |
initJQuery(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment