Less than 2kb global helper function called _async, which loads external scripts asynchronously with callbacks.
Works across all browsers, see Compatibility.
View the live demo.
Add the script to the <head> of your document (or before all other scripts using _async):
<script src="//raw.github.com/niftylettuce/javascript-async-callback/master/async.min.js"></script>Then asynchronously load a script with a callback function:
(function liveDemo() {
var src = '//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js'
function callback() {
alert('It works!')
}
_async.load(document, src, callback)
}())... and you're done!
| IE | FF | Chrome | Safari | Opera | iOS | Opera Mini | Android | Blackberry | Opera Mobile | Chrome Android | Firefox Android |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 5.5+ ✓ | 2.0+ ✓ | 4.0+ ✓ | 3.1+ ✓ | 9.0+ ✓ | 3.2+ ✓ | 5.0+ ✓ | 2.1+ ✓ | 7.0+ ✓ | 10.0+ ✓ | 18.0+ ✓ | 15.0+ ✓ |
- Nick Baugh niftylettuce@gmail.com
MIT Licensed