How to combine several requirejs modules into one?

Hi there,

I am using RequireJS to modularize my code and keep it more maintainable in the future. The website will have 3 distinct page categories. For each one of them I want to load general JS file with all the dependencies that exist across all page categories, jQuery being most obvious one. I have managed to do that already.

For the rest of the pages, I want to have separate JS files. Each page has its own module but I am thinking that it would make more sense if I download several pages modules all at once and this way when the user comes to other pages, he will have the JS file already cached and won’t have to download.

For now I tried to concatenate these modules which did work rather well. However, I am not sure how to load the specific module from a file. So far I am doing this:

require(['./js/common'], function (common) {
    require(['public']);
});

common is the dependencies file and public is my concatenated file with all the dependencies. Inside it has modules for each page but I don’t know how to call a specific one.

Are there any tutorials, known solutions on how to achieve this type of thing?

The RequireJS Optimizer may be of some good use for you here.
A guide on how it can be used is found at http://www.webdeveasy.com/optimize-requirejs-projects/