AMD seems to be the best practice to load javascript modules as-needed.
This should work great on large web-apps where users only use a fraction of the available functionality.
I’ve read about the optimizer, which concatenates all required modules into a single file, and I’ve read about no optimization, i.e. loading each module with a async request.
Both don’t seem to fit this use-case: loading every module with a request might quickly result in a large number of request, whereas optimizing forces you to download all the code.
Is there a way to bundle multiple modules into a single file?
RequireJS supports this use-case with their optimization tool.
With the proper configuration in build.js, it can be configured to bundle multiple modules in multiple files.
Their mapping can be defined in build.js as shown in this example project