在boilerplatejs中,模块似乎是预加载的。
(参见下面的代码)
return [
require('./baseModule/module'),
require('./sampleModule2/module'),
require('./customerModule/module'),
require('./orderSearchModule/module'),
require('./orderListModule/module'),
require('./mainMenuModule/module')
];当涉及到大规模web应用程序(模块重web应用程序)时,对此有什么影响?有没有办法在boilerplatejs中延迟加载模块?
发布于 2012-10-01 17:55:59
Java脚本没有加载东西的反射机制类型。任何需要加载的模块都必须在某个地方注册。这就是为什么加载模块(子上下文)的原因如下:
appContext.loadChildContexts(moduleContexts);(在src/application.js中)
但是上面的代码是关于需求AMD模块的。这基本上是导入不同的JS脚本(每个脚本代表模块的代码)。使用requireJS AMD,脚本(您的源代码)不是延迟加载,而是预加载。这是有意义的,因为您的应用程序源代码应该可以在浏览器中执行。另一方面,当您进行JS优化时,我们无论如何都会创建一个包含所有源代码的脚本。这样就没有必要有单独的脚本文件,或者延迟加载源代码。
但是,延迟加载应该应用于行为(而不是加载代码)。这就是为什么UI组件(ViewTemplate)只在'activate()‘方法中创建的原因。这些只有在用户需要时才会创建。这是一种延迟加载行为,因此应用程序呈现时间更短。
this.activate = function(parent, params) {
// if panel is not created, lets create it and initiate bindings
if (!panel) {
panel = new Boiler.ViewTemplate(parent, template, nls);
...
}
vm.initialize(params.name);
panel.show();
}https://stackoverflow.com/questions/12676333
复制相似问题