Skip to content

Instantly share code, notes, and snippets.

@mikermcneil
Created November 6, 2012 10:46
Show Gist options
  • Select an option

  • Save mikermcneil/4023991 to your computer and use it in GitHub Desktop.

Select an option

Save mikermcneil/4023991 to your computer and use it in GitHub Desktop.
Tiny script to load a remote piece of javascript
// The goal of this script is a dependency-free method of grabbing a remote chunk of javascript (i.e. jQuery)
// loadScript
function loadScript(src,optionalCallback) { var s = document.createElement("script"); s.type = "text/javascript"; s.src = src; var context = document.getElementsByTagName('script')[0]; context.parentNode.insertBefore(s, context); s.async=true; s.addEventListener('load',optionalCallback); }
// Example usage
loadScript("https://some.url",function(e){
console.log("Script loaded successfully!");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment