zjrJS Javascript Library

zjrJS.Doc.lS() - zjrJS Javascript Library

This information lives on a webpage hosted at the following web address: 'https://omegajunior.globat.com/code/zjrjs/'.

How to use zjrJS.Doc.lS() ("load script")

Declaration
zjrJS.Doc.lS(URI url, String id, Optional String type, Optional Number cacheInterval)

Goal
A cross-browser, AJAX-free, cache-aware method to load scripts to the document dynamically and asynchronously.

Typical usage
When you wish to execute as set of scripting functions within the same variable scope (and thus Web Workers won't do), retrieve data in a cache-aware manner from anywhere including other domains (and thus AJAX won't do), and you either know or determine what you get from the script you request (trust your sources!).

In ADUA, an instance of OmegaJunior's own CCS, lS() is used to append menu scripts, forcing a load-on-demand handling. After loading, each menu script calls back to the main script via a predefined function.

In one client's intranet, lS() is used to load and then cache user data, locations data, page tags, etc. In the same site, lS() is used to load personal data, triggering an authentication attempt (a.k.a. logging in).

All three of these speed up the perceived loading of the main page, and due to the caching they reduce bandwidth usage. Because of that caching, the parameter cacheInterval was added.

Don't use this when...


Member Type
Method (no return value).

Parameters
URI url - the path to the place where the script resides you wish to retrieve. It must be either absolute (including a protocol) or relative to the active web page. You can include query parameters.
String id - an identification of your choosing that will serve as the id attribute of the script element lS() will create.
Optional String type - the media type of your choosing that tells the browser what kind of script to expect. Typical and default value: "text/javascript".
Optional Number cacheInterval: cache invalidation interval, in minutes. Omit to specify no cache invalidation. It asks the server to provide a fresh version of the source if that many minutes have passed. (Note that this does not create a repeater.) It appends an extra query parameter named "t" to the url. Note that this doesn't make the source file cacheable: that relies on the http response headers sent by the server.

Special case: if zjrJS.Doc.base is set, lS() will prepend it to the url. See the To-Do List.

Dependencies


Example
<script type="text/javascript" src="zjrJS.version.js" id="zjrJS"></script>
<script type="text/javascript">/* <![CDATA[ */

zjrJS.Doc.aE(window,"load",function(){
//The reader script should be instructed to call back when done loading
zjrJS.Doc.lS("myDataReader.js", "myDataReader");
});

//This is the callback function that myDataReader.js will invoke
function myDataReaderCallback(){
//Now we know the reader is loaded and ready, let's get some data.
//This data script should also call back when done loading.
zjrJS.Doc.lS("myData.js", "myData", 30);
}

function myDataCallback(){
//Now we know the data is loaded and ready, do something with the data
}
/* ]]> */</script>


Note that lS() by itself doesn't cache any data.

Download:

Download zjrJS’ latest stable build (20141202t2322) minified (7.1KB).

Download zjrJS’ latest stable build (20141202t2322) (11.9KB).

Clicky Analytics