Minifyを使用してJSを結合および縮小し、バックボーンアプリのindex.htmlには、次のようなコードブロックがあります。
if (APP._dev === true) {
// So on development, we load all the files individually
$.when(
// Utilities
$.getScript(APP._rootDir + 'app/js/util.js'),
// Models
$.getScript(APP._rootDir + 'app/js/models/Timer.js'),
$.getScript(APP._rootDir + 'app/js/models/Section.js'),
// Collections
$.getScript(APP._rootDir + 'app/js/collections/Timers.js'),
$.getScript(APP._rootDir + 'app/js/collections/Sections.js'),
// Views
$.getScript(APP._rootDir + 'app/js/views/TitleView.js'),
$.getScript(APP._rootDir + 'app/js/views/BackgroundAudioView.js'),
// Router
$.getScript(APP._rootDir + 'app/js/routers/APPRouter.js'),
// Load in our templates file and add each template to a
// proerty visible in our application scope
$.get(APP._rootDir + 'app/js/templates/all.html',function(result){
var tmp = $('<div></div>').html(result);
$('script.template', tmp).each(function(){
APP._templates[this.id] = $(this).html();
});
},'html'),
// Here we create a new deferred object which we will bind
// to JQuery's ready() event.
$.Deferred(function (deferred) {
// DOM Ready. Invokes our APP.init() function.
$(deferred.resolve); // init
})
).done(
APP.init
).fail(
function () { /* fail how you would like */ }
);
} else {
$.when(
// And on prod, we load a combined & minified JS file instead
$.getScript(APP._rootDir + 'min/?g=js'),
// Load in our templates file and add each template to a
// proerty visible in our application scope
$.get(APP._rootDir + 'app/js/templates/all.html',function(result){
var tmp = $('<div></div>').html(result);
$('script.template', tmp).each(function(){
APP._templates[this.id] = $(this).html();
});
},'html'),
// Here we create a new deferred object which we will bind
// to JQuery's ready() event.
$.Deferred(function (deferred) {
// DOM Ready. Invokes our APP.init() function.
$(deferred.resolve); // init
})
).done(
APP.init
).fail(
function () { /* fail how you would like */ }
);
}
次に、Minifyの/min/
ディレクトリにあるgroupsConfigで、jQueryの遅延オブジェクトの読み込み順序に一致するようにビルド配列を定義します。
return array(
'js' => array(
'//' . $rootDir . '/util.js',
'//' . $rootDir . '/models/Timer.js',
'//' . $rootDir . '/models/Section.js',
'//' . $rootDir . '/collections/Timers.js',
'//' . $rootDir . '/collections/Sections.js',
'//' . $rootDir . '/views/TitleView.js',
'//' . $rootDir . '/views/BackgroundAudioView.js',
'//' . $rootDir . '/routers/APPRouter.js'
),
'css' => array(),
);
おそらくDRYほどではありませんが、機能し、ニーズに合わせて調整できます。