Oct 04
James Burke has rapidly of late sequenced through a series of releases of RequireJS file and module loader for JavaScript – reaching Release 0.14.2 (mostly bug fixes) this week.
The software recently gained preliminary support for anonymous modules. Looking forward, Burke has posted a design sketch and code on GitHub (“rough at the moment, mostly scaffolding,” he writes) for a Node-based package tool. Further ahead he sees a RequireJS 1.0 release in the offing.
He writes:
The code has been very usable for a few releases now, but I have kept the release numbers below 1.0 to indicate that the final mix of features were being worked out. With the changes in this release, it feels like the major format changes have landed.
Continue reading »
Tagged with: 0.14.2 • RequireJS
May 16
James Burke is moving quickly with his RequireJS library. He recently posted about the requirements that John Resig has for a script loader for jQuery:
- script loading must be async
- script loading should do as much in parallel as possible. This means in particular, that it should be possible to avoid dynamic nested dependency loading.
- it looks like a script wrapper is needed to allow #1 and #2 to work effectively, particularly for cross-domain loading. It is unfortunate, but a necessity for script loading in browsers.
With the RequireJS 0.11.0 release James feels like he has the features to make that real:
James mentioned a server side scanning tool…. and Kyle Simpson (of LABjs) is almost ready to show something there too.
Continue reading »
Tagged with: 0.11 • jQuery • Ready • Released • RequireJS
Mar 18
A certain someone was talking to me about how they find it interesting that node.js, the JavaScript server framework du jour which loves all things async, starts life with a bunch of synchronous require() calls. Now, this is actually quite fine since the startup of the server is not the issue at hand.
However, if you are running require()-esque loader code in the browser you want to avoid blocking calls else Steve Souders will come over and beat you up.
I have seen a couple of interesting items in this area:
RequireJS
James Burke of Mozilla Messaging has spent a lot of time in the depths of dojo.require(). He has taken another look at the problem and RequireJS a solution that offers:
- some sort of #include/import/require
- ability to load nested dependencies
- ease of use for developer but then backed by an optimization tool that helps deployment
He walks through the problem and why other solutions like LABjs, CommonJS require, and Dojo itself don’t cover all of his bases.
The end result is:
JAVASCRIPT:
-
-
// code that runs asynchronously when the library is loaded
-
require([“some/script.js”], function() {
-
//This function is called after some/script.js has loaded.
-
});
-
-
// defining the module and dependencies
-
require.def(
-
// The name of this module
-
“types/Manager”,
-
-
// The array of dependencies
-
[“types/Employee”],
-
-
// The function to execute when all dependencies have loaded. The arguments
-
// to this function are the array of dependencies mentioned above.
-
function (Employee) {
-
function Manager () {
-
this.reports = [];
-
}
-
-
// This will now work
-
Manager.prototype = new Employee();
-
-
// return the Manager constructor function so it can be used by other modules.
-
return Manager;
-
}
-
);
-
Google Analytics “async add to []” Pattern
When talking to Davis Frank of Pivotal about some Google Analytics code, he pointed me to details about the new GA asynchronous loader that we very excitedly blogged about since GA was such a blocking offender on the Web.
Part of the asynchronous API is that you, the developer create an array, and use the push() method to put commands on a queue. This means that you can start pushing commands immediately.
Then, when the GA code loads asynchronously, it takes over that array and wraps those standard methods. Now it can take the commands and fire them back to GA and push() can do more. Freaking brilliant.
Continue reading »
Tagged with: Asynchronous • JavaScript • loading • RequireJS