Manage JavaScript Dependencies

Posted on April 15th, 2008, by Cristian in Development, Javascript & jQuery

Jon Davis created Using.js, a simple library to manage dependencies with the goals of:

  • Separate script dependencies from HTML markup (let the script framework figure out the dependencies it needs, not the designer)
  • Make script referencing as simple and easy as possible (no need to manage the HTML files)
  • Lazy load the scripts and not load them until and unless they are actually needed at runtime.

To use the script you simply:

// potential scripts are pre-registered first
using.register("jquery", "/scripts/jquery-1.2.3.js");

// later, when actually needed
using("jquery"); // loads jQuery and de-registers jQuery from using

$("a").css("text-decoration", "none");

// or asynchronously

using("jquery", function() {
$("a").css("text-decoration", "none");
});

As we see more and more tactics for getting performance by doing tricks with when scripts are loaded, I expect to see more of libraries like this. The key is working out exactly what script needs to be loaded right away, after the DOM is around, and what can wait for later. How do you want to load the script? Dynamic script element? Via iframe? XHR + eval? They all have pros and cons.

Leave a comment

Advertise / Sponsors

Comments RSS Feed

Recent Comments

  • yuci: ok, i solved the problem, but i will search for a better one. i just noticed, hidden div doesnt show itself...
  • yuci: hey, yeah i downloaded well, and i edited a lot this application, and i can say that, it is a wonderful app....
  • Cristian: No, it’s working as I tested.
  • yuci: is link dead, or just some temporary problem? i cant download zip files.
  • Fredrik: I can’t get this to work. It seems to fail at $order->setShippingAmount( $shipping_amount +...