Last active
November 20, 2015 07:52
-
-
Save Teino1978-Corp/d974591393d771c786c0 to your computer and use it in GitHub Desktop.
include() - load scripts asynchronously w/375 bytes of code - e.g. `include(src, cb)`
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
function include(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); | |
} | |
// usage: | |
include('http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js',function(){ | |
alert('jQuery loaded. yay life') | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment