Carson126 / loadJS

A simple function for asynchronously loading JavaScript files

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

loadJS

A simple function for asynchronously loading JavaScript files

Usage

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>

Limitations

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.

Contributions and bug fixes

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!

About

A simple function for asynchronously loading JavaScript files

License:MIT License


Languages

Language:JavaScript 100.0%