Skip to content

Instantly share code, notes, and snippets.

@Nilpo
Forked from benbalter/conditionally-load-jquery.js
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Nilpo/91ce50041d0c3471d7f2 to your computer and use it in GitHub Desktop.
Save Nilpo/91ce50041d0c3471d7f2 to your computer and use it in GitHub Desktop.
// Conditionally Load jQuery (javascript)
// Source: https://gist.github.com/gists/902090/
var init, loadjQuery;
init = function() {
jQuery(document).ready(function() {
alert('Your Code Here');
});
};
loadjQuery = function() {
var jQ;
if (!(typeof jQuery !== "undefined" && jQuery !== null)) {
jQ = document.createElement('script');
jQ.type = 'text/javascript';
jQ.onload = jQ.onreadystatechange = init;
//jQ.src = '//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js';
jQ.src = '//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js';
return document.body.appendChild(jQ);
} else {
return init();
}
};
if (window.addEventListener) {
window.addEventListener('load', loadjQuery, false);
} else if (window.attachEvent) {
window.attachEvent('onload', loadjQuery);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment