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/CI 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.
The code:
http://github.com/jrburke/requirejsDoc with example on how to use it today with jQuery as standalone library:
http://github.com/jrburke/requirejs/blob/master/docs/jquery.mdMy 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