Skip to content

Instantly share code, notes, and snippets.

@kurtschlatzer
Forked from hjerpbakk/snippet.js
Created August 13, 2012 19:18
Show Gist options
  • Save kurtschlatzer/3343415 to your computer and use it in GitHub Desktop.
Save kurtschlatzer/3343415 to your computer and use it in GitHub Desktop.
Optimised async loading of cross-domain scripts, added js.async=true
(function(doc, script) {
var js,
fjs = doc.getElementsByTagName(script)[0],
add = function(url, id) {
if (doc.getElementById(id)) {return;}
js = doc.createElement(script);
js.src = url;
js.async=true;
id && (js.id = id);
fjs.parentNode.insertBefore(js, fjs);
};
// Twitter SDK
add('//platform.twitter.com/widgets.js', 'twitter-wjs');
// Google+ button
add('https://apis.google.com/js/plusone.js');
// Facebook SDK
add('//connect.facebook.net/en_US/all.js#xfbml=1', 'facebook-jssdk');
// Hacker News
add("//hnbutton.appspot.com/static/hn.js");
}(document, 'script'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment