Created
November 6, 2012 10:46
-
-
Save mikermcneil/4023991 to your computer and use it in GitHub Desktop.
Tiny script to load a remote piece of javascript
This file contains hidden or 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
| // 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