Skip to content

Instantly share code, notes, and snippets.

@stojg
Last active October 3, 2015 06:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save stojg/2411179 to your computer and use it in GitHub Desktop.
Save stojg/2411179 to your computer and use it in GitHub Desktop.
Async loading of social jS with callbacks
(function(d, s) {
var js, fjs = d.getElementsByTagName(s)[0], load = function(url, id, callback) {
if (d.getElementById(id)) {return;}
js = d.createElement(s);js.src = url;js.id = id;js.async=true;
fjs.parentNode.insertBefore(js,fjs);
if(callback!=undefined) {
js.onload=callback;
//Extra for internet explorer
js.onreadystatechange = function () { if(this.readyState == 'complete' || this.readyState == 'loaded') { callback(); } }
}
};
load('//connect.facebook.net/en_US/all.js#xfbml=1', 'fbjssdk', _ga.trackFacebook());
load('https://apis.google.com/js/plusone.js', 'gplus1js');
load('//platform.twitter.com/widgets.js', 'tweetjs', _ga.trackTwitter);
}(document, 'script'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment