Skip to content

Instantly share code, notes, and snippets.

@djprmf
Created October 18, 2015 18:42
Show Gist options
  • Save djprmf/5c7e8f37befdf55d3efe to your computer and use it in GitHub Desktop.
Save djprmf/5c7e8f37befdf55d3efe to your computer and use it in GitHub Desktop.
Load multiple scripts asynchronously
(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;
id && (js.id = id);
fjs.parentNode.insertBefore(js, fjs);
};
// Just a few examples to start
// More can be added in the same way
add('https://apis.google.com/js/plusone.js');
add('//connect.facebook.net/en_US/all.js', 'facebook-sdk');
add('//platform.twitter.com/widgets.js', 'twitter-js');
}(document, 'script'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment