javascriptmodernizrlabjs

combining LABjs and Modernizr and yepnopejs


I've been using LABjs and it's working well.

I'm now trying to make use of the awesome Modernizr, and notice that it uses yepnopejs for conditional resource loading.

Since I do want conditional loading, can I use LABjs and yepnopejs together? Or must I pick one exclusively? If anyone has experience using these together, I'd appreciate your feedback. Thanks!


Solution

  • LABjs can do conditional loading, just like yepnope can (it just doesn't have quite as sexy of an API for that as yepnope).

    $LAB.script(typeof JSON == "undefined" ? "json2.js" : false).wait()
    .script("myotherscript.js");
    

    -or-

    $LAB.script(function(){
       if (typeof JSON == "undefined") return "json2.js";
    })
    .wait()
    .script("myotherscript.js");
    

    So, you should be able to do your loading with LABjs, and your HTML5 feature-testing stuff with modernizr.


    Now, it IS a shame that modernizr also comes with yepnope and that this leads to slightly more code being loaded than you need, since you have two loaders. In that case, you could choose to ditch LABjs and only use yepnope, or you could just overlook that minor issue (for now*).

    I strongly recommend staying with LABjs since its loading functionality under the covers is more robust/future-proof (but not as broad) than yepnope.

    *I'm planning to release "yeahno.js" which will be LABjs underneath, with the yepnope API on top of it, to get the best of both worlds. Then, you can have modernizr, yepnope (API), and LABjs loading all in one, with no extra cost. Stay tuned to http://github.com/getify/yeahno.js.