Skip to content

Instantly share code, notes, and snippets.

@sonyseng
Created April 15, 2014 01:41
Show Gist options
  • Save sonyseng/10695142 to your computer and use it in GitHub Desktop.
Save sonyseng/10695142 to your computer and use it in GitHub Desktop.
Load some javascript from a CDN. Doesn't work if the response header includes Content-Security-Policy prohibiting such actions. (i.e. github)
(function (url, onLoad) {
var script = document.createElement('script');
script.addEventListener('load', onLoad);
script.src = url;
document.getElementsByTagName('head')[0].appendChild(script);
}('https://cdnjs.cloudflare.com/ajax/libs/q.js/0.9.2/q.js', function () {
// Load the Q promises library dynamically and print out the object
console.log(Q);
}))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment