Created
September 27, 2012 04:16
-
-
Save hvergara/3792116 to your computer and use it in GitHub Desktop.
getScript() - load scripts asynchronously w/375 bytes of code - e.g. `getScript(src, cb)`
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
// # getScript() | |
// more or less stolen from jquery core and adapted by paul irish | |
function getScript(url,success) { | |
var head = document.getElementsByTagName("head")[0], done = false; | |
var script = document.createElement("script"); | |
script.src = url; | |
// Attach handlers for all browsers | |
script.onload = script.onreadystatechange = function(){ | |
if (!done && (!this.readyState || this.readyState == "loaded" || this.readyState == "complete") ) { | |
done = true; | |
if (typeof success === 'function') success(); | |
} | |
}; | |
head.appendChild(script); | |
} |
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
// # getScript() | |
// more or less stolen from jquery core and adapted by paul irish | |
function getScript(e,t){var n=document.getElementsByTagName("head")[0],r=!1,i=document.createElement("script");i.src=e,i.onload=i.onreadystatechange=function(){!r&&(!this.readyState||this.readyState=="loaded"||this.readyState=="complete")&&(r=!0,typeof t=="function"&&t())},n.appendChild(i)}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment