Friday, December 31, 2010

Javascript Loaders

LABjs*
The defining characteristic of LABjs is the ability to load *all* JavaScript files in parallel, as fast as the browser will allow, but giving you the option to ensure proper execution order if you have dependencies between files.*

.script("http://remote.tld/jquery.js").wait()
.script("/local/plugin1.jquery.js")
.script("/local/plugin2.jquery.js").wait()
.script("/local/init.js").wait(function(){
initMyPage();
});

The author indicates* that all four of these scripts will load in parallel (if the browsers allows).  The wait() is to control execution order.

Require JS*
There are 5 basic ways to use require.js:
  1. Loading JavaScript files.
  2. Define a module that has other dependencies.
  3. Define an internationalization (i18n) bundle.
  4. Specify a text file dependency.
  5. Specify a JSONP service dependency.*
Use "order!" to execute in series:

require(["order!one.js", "order!two.js", "order!three.js"], function () {
    //This callback is called after the three scripts finish loading.
});

Comparison of LABjs & Require JS.

No comments:

Post a Comment