This post describes how to create a extremly simple Backbone Marionette application using Asynchronous Module Definition or AMD provided by RequireJS.

The Marionette documentation states the following:

It is recommended that you divide your controller objects into smaller pieces of related functionality and have multiple routers / controllers, instead of just one giant router and controller.

Although this is pretty obvious, the documentation never really shows how to achieve this. Probably modules have something to do with it, yet there’s no mention of routers of controllers.

Looking at some examples confirmed that modules were the way to go. The wiki gives a decent explanation on how to use modules with AMD but again, yet again missing vital information on how to bind them with your main application.

My solution consists of loading them in the main application’s initializer.

app.addInitializer(function (){
  require([
    'common/AppRouter',
    'modules/one/OneApp',
    'modules/two/TwoApp'
  ], function(AppRouter){
    new AppRouter();
    Backbone.history.start({pushState: true})
  });
});

I’m not sure whether this is the proper way to go due to the lack of documentation and guidelines. Either way, it’s a clean way to create modular encapsulated logic as what modules are intended for.

GitHub Repository