I would like to offer a require() function as provided in RequireJS as a script loader for jQuery.
While RequireJS can be used today without integration into jQuery core, there are benefits with integrating RequireJS, similar to how Sizzle is integrated, with jQuery core:
export jQuery as a module to be used by the module system supported by RequireJS
The "baseUrl" to find all scripts would be relative to jquery.js
more robust handling of async scripts that should be loaded before jQuery.ready() fires its callbacks.
Longer term, the encapsulated scopes of RequireJS-supported modules could be used to build jQuery core from a set of discrete modules (this is not strictly needed, just another integration option).
RequireJS aims to work with CommonJS modules as best as possible, given the constraints of browser loading, but still allows "simple" use by just loading some stand-alone JS files, or in jQuery's case, allowing any easy way to load existing plugins.
I am participating in the CommonJS group to try to get a module "transport format" that works best in the browser, and RequireJS implements the latest transport proposal: http://wiki.commonjs.org/wiki/Modules/Transport/C
I have a simple conversion script that converts normal CommonJS modules to the browser-friendly require() format used by RequireJS and as specified in Transport/C.
RequireJS has an optimization tool that allows you to builld all your JS files into bundles and will soon have the ability to optimize CSS (inline @import calls, remove comments).
If you think RequireJS might be a close fit for jQuery, but need some tweaks or want to discuss more of its internals, I am happy to oblige.
My fork of jQuery that does an initial integration of RequireJS (uses the 2.4KB minified/gzipped bare bones version of RequireJS): http://github.com/jrburke/jquery
I heard about the jQuery require that is shown as part of this changeset: http://github.com/jquery/jquery/commit/998cb005fc378188b3bae319e391d1b7881b7ad2 I work on Dojo's module loader, and have a new standalone (no other library dependency) script loader here: http://code.google.com/p/runjs/wiki/RunJs The goal is to keep RunJS compatible with the goals of CommonJS (avoiding globals mainly) but still allow for a module syntax that works well natively in the browser. It does not use XHR calls, just script tags. Works before page load and after page load. It also handles loading regular scripts that are not coded as modules: run(["some/script.js", "another/script.js"], function() { //This callback is fired when both scripts load }); For scripts that do follow the module syntax and have dependencies, it properly traces the module dependencies and calls the module definition functions in the correct order. It would be ideal if more of the JS libraries started to standardize on a script loader. I am happy to work out changes to RunJS if jQuery might find it useful to use. For instance, the entry point does not have to be called run(), I am considering switching to script() since it handles general script loading and callbacks when scripts are loaded. It also might be good to pull out a script loader from the core jQuery library, if only to keep the separation of concerns easier to track. RunJS has plugins for i18n string bundle loading, and also can load text files (like HTML snippets) via async xhr, then inline those text files as part of a build process. But I may be misunderstanding the scope of jQuery's require. In any case, I just wanted to see if there was some common interest and if we might be able to coordinate our efforts. Thanks for your time, James Burke --