1

I would like to start incorporating LABjs into my project but I want to know if there is anyway to conditionally load scripts. For example, something like:

$LAB
   .script('framework.js').wait()
   .script(function(){
       if(es){
          return  'es.js';
       }else{
          return '';
       }
   })

I have not tried this but am sure it will not work. Is there a more elegant way of doing this?

Thanks

4

3 回答 3

4

Actually, LABjs now (and for awhile) has supported conditional chaining... in a couple of ways. Firstly, you can pass a function to a .script() call, and that function can have conditional logic inside it that returns different URL strings (or nothing at all) depending on the conditions. Secondly, chains are now fully resumable (as of 2.0, being released in a few days), so you can do an easier form of the "simulated chaining" mentioned in that above blog post, by simply saving the state of a chain, and then picking up and adding to it later, like:

var $L = $LAB.script(...).script(...);

if (...) { $L = $L.script(...).wait(...);

// ...

$L = $L.script(...).....
于 2011-05-19T20:23:18.630 回答
0

http://blog.getify.com/2010/02/simulated-chaining-in-javascript/

the answer ain't pretty but it's here

于 2010-08-05T18:55:33.357 回答
0

I use LABjs for most of my projects, but when I need conditional chaining I use yepnode. It is fairly similar to LABjs, but I prefer how yepnodes handles conditional loading.

于 2011-12-06T11:12:13.097 回答