Skip to content

Instantly share code, notes, and snippets.

@skrings
Forked from 140bytes/LICENSE.txt
Created June 23, 2011 19:17
Show Gist options
  • Save skrings/1043377 to your computer and use it in GitHub Desktop.
Save skrings/1043377 to your computer and use it in GitHub Desktop.
140byt.es -- scriptLoader

140byt.es

A tweet-sized, fork-to-play, community-curated collection of JavaScript.

/**
* @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);
}
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);}
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.
{
"name": "scriptLoader",
"description": "Simple script loader - preserving order asynchronously",
"keywords": [
"script",
"loader",
"async",
"order"
]
}
<!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>
@CapMousse
Copy link

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