body 終了タグの直前から Require.js を呼び出しています。
<script data-main="assets/scripts/src/main.js" src="assets/scripts/lib/requirejs/require.js"></script>
</body>
これが私のmain.js
内容です:
requirejs.config({
urlArgs: "bust=" + (new Date()).getTime(), // override browser cache
});
require(['views/appView'], function (App) {
App.initialize(); // this is just to test the module is actually loading
});
appView.js には以下が含まれます。
define([
'modernizr',
'jquery',
'underscore',
'backbone',
'common', // this module has about 4 other dependencies too
'dust',
'routers/main',
'views/main'
], function (Modernizr, $, _, Backbone, Common, dust, router, mainView) {
// This is supposed to load, even if jQuery loads after the DOM ready event
$(document).on('ready', function () {
console.log("I don't want to play nice");
});
return {
initialize: function () {
console.log("Init");
}
}
});
残念ながら、これはまったくconsole.log("I don't want to play nice");
起こりません。
これは、私のネットワーク タイムラインが Chrome Dev Tools でどのように見えるかです。ご覧のとおり、jQuery がロードされる前に DOM 準備完了イベントが発生しますが、私の知る限り、jQuery はこれを処理する方法を知っています! だから私は迷っています。