A simple function for asynchronously loading JavaScript files
- [c]2014 @scottjehl, Filament Group, Inc.
- Based on Surefire Dom Element Insertion by Paul Irish
- Licensed MIT
Place the loadJS
function inline in the head
of your page (it can also be included in an external JavaScript file if preferable).
Then call it by passing it a JavaScript URL:
<head>
...
<script>
// include loadJS here...
function loadJS( src ){ ... }
// load a file with loadJS
loadJS( "path/to/script.js" );
</script>
...
</head>
loadJS
does nothing to manage execution order of requested scripts, so we do not advise using it to load multiple javascript files that depend on one another. It simply fetches a script and executes it as soon as possible. You can certainly use loadJS
to load multiple scripts as long as those scripts are designed to execute independently of any other scripts being loaded by loadJS
.
Both are very much appreciated - especially bug fixes. As for contributions, the goals of this project are to keep things very simple and utilitarian, so if we don't accept a feature addition, it's not necessarily because it's a bad idea. It just may not meet the goals of the project. Thanks!