我可以帮助您翻译这段内容。这是关于使用requireJS仅在需要时加载模块的概念方面的帮助请求。
这是我的main.js文件。
这是我的main.js文件。
require(['jquery', 'path/somemodule'],
function($, somemodule) {
$(document).ready(function() {
somemodule.init()
})
})
并且在 somemodule.js 中
define(['jquery', 'path/someothermodule'], function ($, someothermodule) {
"use strict";
var somemodule;
somemodule = {
init: function () {
someothermodule.init()
}
}
return somemodule;
)}
现在,somemodule.js和someothermodule.js被加载到所有页面上。我该如何只在需要时加载它们?
main.js
需要path/somemodule
,而somemodule.js
需要path/someothermodule
。因此,每次包含main.js
时,它也会包含somemodule.js
和someothermodule.js
。 - Kevin B