public
Last active

Javascript loading example

  • Download Gist
gistfile1.htm
HTML
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
<!DOCTYPE html>
<html>
<head>
<script>function L(B,D){var A=document.createElement("script"),C=document.documentElement.firstChild;A.type="text/javascript";if(A.readyState){A.onreadystatechange=function(){if(A.readyState=="loaded"||A.readyState=="complete"){A.onreadystatechange=null;D()}}}else{A.onload=function(){D()}}A.src=B;C.insertBefore(A,C.firstChild)};
 
// async loading of javascript files, starting asap.
L("http://example.com/example.js",function () {
doSomething();
});
L("http://example.com/foo.js", function () {
fooSomeBar();
});
</script>
<title>Javascript loading example</title>
</head>
<body><p>When the JS loads, you'll see something being done, and some bar being fooed.</p></body></html>

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.