Friday, January 23rd, 2009

Dependency Management with the with YUI Loader

Category: JavaScript, Yahoo!

Simon Tiffert told us of a co-workers post on loading your JavaScript modules with the YUI Loader.

The post discusses how you can use the loader for your own libraries, giving you full dependency management, similar to that of the Dojo loader and others:

As YUI comes with a special module for loading dependencies, the YUI Loader Utility, we explored if we could use YUI for our needs. The Loader’s feature list reads like our wish-list:

  • Reliable, sorted loading of dependencies
  • Safe, efficient mechanism for adding new components to a page on which YUI may already be present.
  • Automatic use of rolled-up files.

So we’ve developed our own solution on top of the YUI loader for our Framework. It consists of two components: A Compile-time dependency analyzer and a configuration file generated by the dependency analyzer that tells YUI how to load our modules.

Then we get to see the details on how you take this API:


  1. var loader = agimatec_config.getLoader()
  2. loader.require("agimatec.topic");
  3. loader.insert(function(){
  4.     // use agimatec.topic and ALL of its dependencies here !!!!
  5. });

and have it walk the stack, including the way to annotate your module:


  1. // @@module agimatec.topic
  2. // @@requires event, agimatec.datatypes
  4. // Module code goes here
  5. // ...
  7. // Tell the loader that this module has been loaded
  8. YAHOO.register("agimatec.topic", agimatec.topic, {version:'1.0',build:'000'});

Posted by Dion Almaer at 7:28 am

3.5 rating from 25 votes


Comments feed TrackBack URI

YUI Loader downloads scripts sequentially. It’s possible to load scripts in parallel while also ensuring execution order. This would be a nice enhancement to YUI Loader.

Comment by souders — January 23, 2009

I spent quite a bit of time playing with YUI loader to load my own modules along with the standard YUI modules. Seems like a really nice way to do things, unfortunately I found the performance hit compared to script tags unbearable. Hopefully YUI 3.x will see an improvement in this area.


Comment by patspam — January 24, 2009

Leave a comment

You must be logged in to post a comment.