Monday, February 14, 2011

RequireJS 0.23.0 Released

RequireJS 0.23.0 is available for download.

  • The baseUrl defaults have changed. This will likely be the biggest impact, and may require a change in your code.
  • Node is now the default JS engine used for the optimizer. It is blazing fast. However, not everyone can switch to the new hotness, so it is still possible to run the optimizer in Java/Rhino. But Node is the default, so if you use and want to use Java, update to
  • UglifyJS is the default minifier for the optimizer, since it runs in both Node and Rhino.
  • The Node adapter is updated and should match Node's native behavior for any npm-installed module, but see the release notes for more detail.
See the release notes for more information.

The env plugin

One of my favorite things in this release is how the optimizer can run on either Node or Rhino. The optimizer is structured as a set of RequireJS modules and a new plugin: the env loader plugin. That plugin tells RequireJS to load a particular module based on the environment that is running RequireJS.

To indicate a module dependency that varies based on the environment, modules use dependencies that look like "env!env/file", and the env loader plugin will load "node/file" if in Node or "rhino/file" if in Rhino.

While the env plugin in its current form is not ready for outside use (in particular it needs more work to be useful in an optimizer build), I believe it shows the way forward for doing environment-based branching of module loading. In particular, it can be seen as a great alternative to the concept of "overlays" that have come up in some approaches to CommonJS packages.

jQuery integration

The integrated jQuery+RequireJS file has not been updated to jQuery 1.5.0 yet. I want to wait for jQuery 1.5.1 since it may contain a fix related to jQuery.readyWait which is used by RequireJS.

Next up

With the conversion to using Node as the default optimizer engine, the code is one step closer to a 1.0 release.

I want to do another release that breaks out the text, i18n and order plugins into a separate repo or repos. Right now they have a magic status that will cause problems in the long run.

I also want to deliver the optimizer just as one script file, instead of a small collection of modules as it is now. This is possible since the optimizer is written as RequireJS modules/loader plugins, and not something that would be easy to do if they were CommonJS modules. I may punt on this though in the interest of getting to 1.0 sooner.

It may also make sense to break out the optimizer into its own repo, but again I may punt on that to reach 1.0 faster.

So hopefully just one or two more releases before going to 1.0. Depending on the timing of jQuery 1.5.1, there may be one additional release in that set.


Busticated said...

Very cool! Can't wait to try the new stuff. Thx for being awesome!

spiderman said...

good change for the baseUrl. The default baseUrl indeed should be where the html file resides.

This should prevent possible confusion or struggling people could have when they start using requirejs. (just like I did :->)

By the way, I just start testing my requirejs application against ie9 rc. All of a sudden, it now emits "Mismatched anonymous require.def modules" error that I have never seen on other browser. Any hint where I can start looking for problem?

James Burke said...

spiderman: I just tried the requirejs tests in the latest platform preview for IE9, which should match the RC, the platform preview has version number 1.9.8080.16413.

The tests passed for me, and that is using RequireJS 0.23.0. Normally "mismatched anonymous require.def" calls means there is more than one anonymous require.def/define call in a file.

If you have more details or a test case I can try, feel free to post it to the requirejs list.

spiderman said...

The program runs fine if it is in IE7 doc mode. But it emits that error message when switched to IE9 plus IE9 doc mode (via F12).

James Burke said...

spiderman: I'll need more information, maybe a link to a test case or something I can try to debug, because the unit tests may not be capturing the case you are hitting.

spiderman said...

There are many files in my application, I need to sort them out to figure out what is going on. Will let you know once I have found out the problem. Thanks.

eevmq said...

Hi...the jquery 1.5.1 us out...Are you planning integrate this new release to the requireJS....I would like to use the best of both world!!!

James Burke said...

eevmq: Yes, I want to do a release by the end of this coming weekend.

In the meantime, you can see this thread on how you can use jQuery 1.5.1 with the current RequireJS release.

eevmq said...

Thanks for your quick response, I hope to use soon RequireJs and besides propose it to my developers friends.... Thanks again for your brilliant work.... english is not very good, it's not my native languaje.