Skip to content

Instantly share code, notes, and snippets.

@hjerpbakk
Forked from necolas/snippet.js
Created August 11, 2012 10:07
Show Gist options
  • Save hjerpbakk/3323368 to your computer and use it in GitHub Desktop.
Save hjerpbakk/3323368 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