Skip to content

Instantly share code, notes, and snippets.

@lodestone
Forked from tobsn/jquery.loader.js
Created December 15, 2010 18:59
Show Gist options
  • Save lodestone/742420 to your computer and use it in GitHub Desktop.
Save lodestone/742420 to your computer and use it in GitHub Desktop.
(function(j,q,u,e,r,y,r,o,x){try{o=jQuery;if(o&&(!r||(r&&o.fn.jquery==r))){x=true}}catch(r){}if(!x||(r&&o.fn.jquery!=r)){(q=j.createElement(q)).type='text/javascript';if(r){q.async=true}q.src='//ajax.googleapis.com/ajax/libs/jquery/'+(r||1)+'/jquery.min.js';u=j.getElementsByTagName(u)[0];q.onload=q.onreadystatechange=(function(){if(!e&&(!this.readyState||this.readyState=='loaded'||this.readyState=='complete')){e=true;x=jQuery;jQuery.noConflict(true)(function(){y(x)});q.onload=q.onreadystatechange=null;u.removeChild(q)}});u.appendChild(q)}else{y(o)}})(document,'script','head',false,false,(function($){$(function(){
/* code goes here */
console.log($.fn.jquery);
})}));
// readable:
(function (j, q, u, e, r, y, r, o, x ) {
// IE8 undefined crash fix
try {
// check if we can assign jQuery
o=jQuery;
// if jquery is defined and version is not set or version is set and matches the existing one
if( o && ( !r || ( r && o.fn.jquery == r ) ) ) {
x = true;
}
}
catch(r) {}
// if jquery isnt set or version is defined and its not matching
if( !x || ( r && o.fn.jquery != r ) ) {
(q = j.createElement(q)).type = 'text/javascript';
if (r) { q.async = true; }
// dont need http|https - /1/ means latest 1.x version
q.src = '//ajax.googleapis.com/ajax/libs/jquery/'+(r||1)+'/jquery.min.js';
u = j.getElementsByTagName(u)[0];
// onload event for callback
q.onload = q.onreadystatechange = (function () {
// first fire when completely loaded and parsed & check if this happened before
if (!e && (!this.readyState || this.readyState == 'loaded' || this.readyState == 'complete')) {
e = true;
// copy space into new var, release control and execute callbacks with passed in own version of jQ
x = jQuery;
jQuery.noConflict(true)(function(){y(x);});
// IE memory leak protection
q.onload = q.onreadystatechange = null;
u.removeChild(q);
}
});
u.appendChild(q);
}
else {
// jquery is already there and version matches or we dont care about version
y( o );
}
// async callback
})(document, 'script', 'head', false, false, (function ($) {
$(function(){
/* code goes here */
console.log( $.fn.jquery );
});
// version if needed - optional (see compressed version above)
}),'1.4.2');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment