View on GitHub


Small JS script loader utility; allows client-side script substitution.

Download this project as a .zip file Download this project as a tar.gz file


loadScript() is a global function for performing asynchronous script loads.

Run unit tests.


How does that work, exactly?

Include loadScript.js via a script tag:

    <script src="loadScript.js" type="text/javascript"></script>

If you want to make use of the URL substitution feature, do this:

    loadScript.key = 'my_localStorage_key';

Actually loading a script is easy:

    var jqURL = '//';
    loadScript(jsURL, function () {
        // jQuery is now loaded!

Now if you, as a developer, want to test out your production site with the non-minified jQuery source for debugging purposes, just use the browser's dev tools to set a localStorage value:

    localStorage.setItem('my_localStorage_key', '[[".min",""]]');

Now when you refresh the page, loadScript() will perform a string substitution on your URLs to remove the '.min' substring. This will only affect you, not other users of the site.

The localStorage value must be a valid JSON stringified array of arrays, where each inner array has exactly two elements: [<searchtext>,<replacetext>]