A tweet-sized, fork-to-play, community-curated collection of JavaScript.
-
-
Save skrings/1043377 to your computer and use it in GitHub Desktop.
140byt.es -- scriptLoader
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
/** | |
* @param {String} a Path to the script | |
* @param {function} b Optional callback executed onload | |
*/ | |
function(a,b,c,d,e){ | |
d=document; | |
c=d.createElement('script'); | |
c.src=a; | |
e=!b; | |
c.onload=function(){ | |
!e&&b();e=!0; | |
}; | |
d.body.appendChild(c); | |
} |
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
function(a,b,c,d,e){d=document;c=d.createElement('script');c.src=a;e=!b;c.onload=function(){!e&&b();e=!0;};d.body.appendChild(c);} |
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
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | |
Version 2, December 2004 | |
Copyright (C) 2011 YOUR_NAME_HERE <YOUR_URL_HERE> | |
Everyone is permitted to copy and distribute verbatim or modified | |
copies of this license document, and changing it is allowed as long | |
as the name is changed. | |
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | |
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION | |
0. You just DO WHAT THE FUCK YOU WANT TO. |
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
{ | |
"name": "scriptLoader", | |
"description": "Simple script loader - preserving order asynchronously", | |
"keywords": [ | |
"script", | |
"loader", | |
"async", | |
"order" | |
] | |
} |
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
<!DOCTYPE html> | |
<head> | |
<title>Poor man's script loader</title> | |
</head> | |
<body> | |
<div>Expected value: <b>1.6.1</b></div> | |
<div>Actual value: <b id="ret">Loading</b></div> | |
<script> | |
/** | |
* @function | |
*/ | |
var scriptLoader = function(a,b,c,d,e){d=document;c=d.createElement('script');c.src=a;e=!b;c.onload=function(){!e&&b();e=!0;};d.body.appendChild(c);} | |
scriptLoader( | |
'https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js', | |
function(){ | |
document.getElementById( "ret" ).innerHTML = window.jQuery.fn.jquery; | |
} | |
); | |
</script> | |
</body> |
Yep, it need the c.onreadystatechange
:
c.onload=c.onreadystatechange=function(){
!e&&b();e=!0;
};
but it's 152 bytes
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This script loader won't work in IE < 9.