Created
June 20, 2013 21:49
-
-
Save gormus/5827011 to your computer and use it in GitHub Desktop.
Load JavaScript Asynchronously. Usage: _async('//example.com/script.js', 'dom-id'); Taken from Twitter and Facebook widget loader scripts and altered a little bit. :-P
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
/** | |
* Load JavaScript Asynchronously | |
* | |
* usage: _async('//example.com/script.js', 'dom-id'); | |
*/ | |
function _async(src, id) { | |
setTimeout( | |
function(d, s, id) { | |
var js, fjs = d.getElementsByTagName(s)[0]; | |
if (d.getElementById(id)) { | |
return; | |
} | |
js = d.createElement(s); | |
js.id = id; | |
js.src = src; | |
fjs.parentNode.insertBefore(js, fjs); | |
} (document, 'script', id), | |
0 | |
); | |
} |
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
// Minimized. | |
function _async(src,id){setTimeout(function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(d.getElementById(id))return;js=d.createElement(s);js.id=id;js.src=src;fjs.parentNode.insertBefore(js,fjs);}(document,'script',id),0);} | |
_async('//example.com/script.js', 'dom-id'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment