Skip to content

Instantly share code, notes, and snippets.

@furf
Forked from tobsn/jquery.loader.js
Created December 11, 2010 17:04
Show Gist options
  • Save furf/737468 to your computer and use it in GitHub Desktop.
Save furf/737468 to your computer and use it in GitHub Desktop.
(function(j,q,u,e,r,y){if(typeof(jQuery)=='undefined'){(q=j.createElement(q)).type='text/javascript';if(r){q.async=true;}q.src='//ajax.googleapis.com/ajax/libs/jquery/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;y();q.onload=q.onreadystatechange=null;u.removeChild(q);}});u.appendChild(q);}else{y();}})(document,'script','head',false,false,(function(){$(function(){
/* code goes here */
});}));
// readable:
(function (j, q, u, e, r, y) {
if (typeof(jQuery) == 'undefined') {
(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/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;
// execute your jquery code now
y();
// IE memory leak protection
q.onload = q.onreadystatechange = null;
u.removeChild(q);
}
});
u.appendChild(q);
}
else {
// looks like jquery is already loaded - just execute code right away
y();
}
// async callback
})(document, 'script', 'head', false, false, (function () {
$(function(){
/* code goes here */
});
}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment