Latest Release§ 1

require.js 1.0.8 Minified With Comments

All you need to start using require.js in the browser.

Sample RequireJS 1.0.8 + jQuery 1.7.2 project Download

A zip file containing a sample project that uses jQuery and RequireJS.

r.js: Optimizer and Node and Rhino adapter Download

The r.js file allows you to run the optimizer as well as run modules in Node or Rhino.

If you are running in Node, and want to use npm to install this file via npm, see the Use with Node page for more information.

For information on its use, as well as how to get the JAR files to run it under Rhino, see the r.js README.

Plugins§ 2

These are useful loader plugins that have the same license terms as require.js itself. Download the plugin file and place it as a sibling to your "data-main" main.js script.

text Minified With Comments

Load text files and treat them as dependencies. Great for loading templates. The text strings can be inlined in an optimized build when the optimizer is used.

domReady Minified With Comments

Wait for the DOM is ready. Useful for pausing execution of top level application logic until the DOM is ready for querying/modification.

order Minified With Comments

Load script in the order specified in the dependency array. Useful for existing scripts that have implied dependencies instead of calling define() to create modular code.

cs (CoffeeScript) With Comments

Load files written in CoffeeScript. Includes a version of CoffeeScript, only this one file is needed. With this plugin, it is easy to code in CoffeeScript in the browser, it can participate in the optimizer optimizations, and it works in Node and Rhino via the RequireJS adapter. This is the best way to do cross-environment, modular CoffeeScript. The project home has more information on how to use it.

i18n Minified With Comments

Load string bundles used in internationalization (i18n) that are made up of separate country/language/locale-specific bundles.

Release Notes§ 3

1.0.8

Small bug fixes to:

1.0.7

Small bug fixes to:

1.0.6

Main purpose of the release is to fix a regression in 1.0.5 where the optimizer's "dir" config option was not applied correctly when passed on the command line.

The other notable change: the optimizer now supports onBuildRead and onBuildWrite functions that are called when JS modules are read or written for an optimized build layer. This allows doing some regexp work to modify their contents.

Small bug fixes to:

1.0.5

Small bug fixes to:

1.0.4

Small bug fixes to:

1.0.3

Small bug fixes to:

1.0.2

Small bug fixes to:

1.0.1

Just small bug fixes related to:

  • allowing full URLs for simplified CommonJS wrapped modules
  • AST parsing of dependencies for modules that use a variable for the factory function
  • catching more cases that should have the "namespace" optimizer option applied

Detailed list of changes for require.js and the r.js optimizer:

1.0.0

Same as RequireJS 0.27.1 release, with some document updates and a small fix to the optimizer's regular expression for converting CommonJS modules to AMD.

0.27.1

RequireJS 1.0 release candidate. Small bugfixes for 0.27.0:

  • define(id, function () {}) where the function has require('') dependencies will now be scanned for dependencies. Allows for smaller universal module adapters.
  • Loader plugin that depends on a different plugin's loaded resource works as it did in 0.26.0.
  • Optimizer: update UglifyJS to 1.1.
  • Optimizer: semicolons are inserted between files if concatenating would cause errors.
  • Optimizer: always strip BOM files on all platforms when file transforms/concatenations are done.
  • Optimizer: allow override of modules used in optimizer. Example.
  • Optimizer: allow copying of .directories via build config option.
  • Optimizer: Resolving paths for .js dependencies might fail if an appDir was not part of the config.

0.27.0

RequireJS 1.0 release candidate.

  • require.ready() has been removed. In its place, use the domReady plugin. This allows better interoperability with other AMD loaders and better separation of concerns.
  • A new wrap config option for the optimizer is available, for wrapping built code in a function. Allows for better API hiding and tiny builds with the almond API shim.
  • The order plugin is improved for IE.
  • Loader plugins can now have dependencies and they will work in the optimizer, as long as the dependencies work in the optimizer environment (Node, Rhino).
  • The namespace config option for the optimizer is more robust.
  • Removed require.def(), use define() instead.
  • Removed module.setExports, use module.exports instead.

0.26.0

  • npm install requirejs to allow require("requirejs"). This allows you to: This is now the recommended path for using RequireJS in Node. More information on the Use with Node page.
  • UglifyJS in the minifier is updated to 1.0.6. The upside: now has() branch trimming now works with the default minifier.
  • Fixes for running under Node on Windows using the native node.exe builds that are now available in the Node 0.5.x series. Now there is less of a need to use Java to drive the RequireJS Optimizer!
  • Configuration is now done via a require.config({}) call, to get in line with the amdjs require API. The old require({}) method works on the global require() for backwards compatibility, but the suggested API going forward is require.config({}). The API doc has been updated to show proper usage.
  • There is a namespace option now for builds, to allow moving require() and define() calls under a different namespace. This allows you to build an optimized file that uses RequireJS but does not interfere with any other AMD loader on the page, and you can make sure only your modules are loaded in that namespaced object.
  • The default error behavior when a define() factory function throws an error is to not catch it. The catching done in 0.25.0 made it more difficult to debug. However, there are some situations where catching the errors is preferred. Setting the config value catchError.define = true will switch to catching the errors and allow processing via require.onError()
  • Closure Compiler in the optimizer was updated. As a result, the code to invoke Closure Compiler changed, and will likely only work with the latest Closure Compiler release. You can grab a version known to work with the optimizer in the optimizer's lib/closure directory.
  • There is now a pragmasOnSave build option, which is used in the require-cs CoffeeScript loader plugin build profile to strip out the CoffeeScript compiler after a build. The end result: tiny build layers of converted CoffeeScript code.

0.25.0

The awesome part: the optimizer is now just one JS file! It also doubles as a bootstrap script that supports the full capability of AMD modules and loader plugins in Node and in Rhino.

To use the optimizer, pass the "-o" option to r.js:

    node r.js -o app.build.js

To run your AMD-based project via the adapter (assuming server.js is your top-level AMD module):

    node r.js server.js

There is more information about running AMD modules in Node. The optimizer docs have been updated to the new optimizer syntax, and the r.js script has its own project now, to allow releases that are decoupled from require.js.

Other highlights:

  • The loader plugin API changed to allow plugins to create cross-domain-accessible resources. The main use case: you use the text plugin to dynamically load text resources, but you want to deploy those scripts to a CDN. See the text plugin's implementation of writeFile() as an example.
  • There is now a global requirejs() function object that is the same as the old global require() function object. This should allow RequireJS to work better in environments like Mozilla Chromeless, which already have a built-in require() function that does not have full AMD/loader plugin capabilities.
  • It is now possible to specify the precise version of jQuery to allow in a RequireJS context. This is useful if you know of other scripts that load different versions of jQuery on a page.

Some changes in the name of compatibility with other AMD module loaders and Node:

  • The "lib" directory configuration in package support was removed. It was always very awkward to support, and Node no longer supports it, so it was enough justification to remove it.
  • Relative module IDs are now relative to the related module ID, not the related module ID path.
  • includeRequire in the optimizer config was removed, Use a paths config to include require.js instead. See the Optimization docs for more details.

A small change to the context-specific require() passed to a loader plugin's load() call: require.isDefined() is now require.defined() and there is require. specified().

0.24.0

  • Support for IE 9. It has a non-conformant script loading behavior that necessitated the change. It would be ideal if IE 9 would change the behavior to be conformant.
  • Changes to jQuery integration:
    • jQuery 1.5.1 included in sample project.
    • No more bundled RequireJS and jQuery file. RequireJS includes special code to detect jQuery as a module, so the combined file is not necessary, and this approach makes it easier to swap in new versions of jQuery as they are released. (Changed on April 1, 2011 back to the old integrated sample)
    • Because of that change, the jQuery sample project uses the new priority: config approach. (Changed on April 1, 2011 back to the old integrated sample)
  • allplugins-require.js has been removed. Plugins are no longer bundled with require.js or in the sample jQuery project. There are separate download links to the existing plugins on the download page. Special treatment of these plugins has also been removed from the require.js source, so those plugins behave like any other loader plugin.
  • There is now a CoffeScript plugin. It makes it easy to code in CoffeeScript in the browser, it can participate in the optimizer optimizations, and it works in Node and Rhino. This is the best way to do cross-environment, modular CoffeeScript.
  • Bug fixes.

0.23.0

  • Calculation of baseUrl changed. This affects the jQuery Sample project, which has been updated in this release. Instead of baseUrl defaulting to the directory containing require.js, it now defaults to the HTML page's directory. If data-main is used, then the directory used in that attribute becomes the baseUrl. Explicitly setting baseUrl in the configuration overrides the aforementioned defaults.
  • The RequireJS optimizer now uses Node by default. So, build.sh/.bat are now Node-based. Java/Rhino is still supported via the buildj.sh/.bat scripts.
  • UglifyJS is now the default minifier for the optimizer, since it works both in Node and in Rhino. However, UglifyJS does not do if/else dead code removal, so the has() optimization is not that great when using UglifyJS. Hopefully this will change in a future version of UglifyJS. If you want the full has() optimization, Closure Compiler can still be used, either by using buildj.sh to use Java/Rhino to do the optimization work, or by running Closure Compiler yourself after the optimizer runs.
  • The behavior of the Node adapter, r.js has changed. It now assumes that any module found via the RequireJS config uses define() to define modules. If a module is not found via the RequireJS path config, r.js uses Node's native require() function and its pathing rules to find the module. This allows the most compatible use of npm-installed modules. However it means you should not include RequireJS configuration for npm-installed modules/packages.
  • The r.js adapter now works in Node and Rhino.
  • The config option, baseUrlMatch has been removed, since the data-main baseUrl rule mentioned above removes the need for it.
  • Some important fixes around loader plugins: a fix to allow multiple modules to use the same plugin resources as a common dependency, and to allow loader plugins that use a define() function callback to work in the optimizer.
  • A fix for the use of jQuery's readyWait capability when jQuery is detected and used as a module.
  • Some directory shuffling related to making the rhino and node adapters the same for use in command line tools and in the r.js adapter.

0.22.0