Manage JavaScript Dependencies

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

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

How to Be a Rockstar Freelancer
Comments RSS Feed

Recent Comments

  • Julian Gruber: Thank you! Following those advices really can make a big difference for the success of a webapp.
  • Tom Humes: Nice Site layout for your blog. I am looking forward to reading more from you. Tom Humes
  • admin: Yes, it does the same. Basic I just get the object $(”#nicemenu span.head_menu”) once, and applied the...
  • André Beaudry: Hi, I would like to know why : $(”#nicemenu span.head_menu”).mouseov er(function(){...
  • admin: Try to change the z-index to the menu container in my example div #nicemenu. The first one should have for ex....