Created
October 18, 2015 18:42
-
-
Save djprmf/5c7e8f37befdf55d3efe to your computer and use it in GitHub Desktop.
Load multiple scripts asynchronously
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
(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