There are many scripts for loading JavaScript. One of my favorites is RequireJS. David Walsh wrote an article about loading Mootools using RequireJS but his technique requires loading mootools core as a whole. What about loading the Mootools modules separately?

Mootools, downloaded from github, comes with packaged with a utility called Packager. I wrote an article on using this tool. It is great for packaging your code prior to deployment but it doesn't work for dynamic loading in the client. Aaron Newton created a useful tool called Depender that dynamically builds a script for your page. His solution requires running Django on your server. This isn't always possible with shared hosting.

RequireJS is great for loading Javascript files. And because of its extensibility using plugins, it becomes even better. I created a Mootools plugin that has the current dependency model for Mootools core 1.4.1 and more It uses this model to dynamically determine which class files are needed by your page and loads them using RequireJS. It also allows you to specify your own files and the required dependencies.

This is very useful during development. Because RequireJS also comes with a build tool, you can use the plugin and configuration to build a production ready script. Check out the project page for more information.