如何解决ExtJS"同步加载& quot;警告 [英] How to tackle ExtJS "Synchronously loading" warning
问题描述
将ExtJS 4+与异步加载会熟悉这种警告:
When using ExtJS 4+ with asynchronous loading one would be familiar with this sort of warning:
[Ext.Loader] Synchronously loading 'MY.particular.module';
consider adding Ext.require('MY.particular.module') above Ext.onReady
如何确定哪个JavaScript模块(例如控制器,组件等)引起此警告?IE.
How to identify which JavaScript module (be it a controller, a component, etc) is causing this warning? I.e. the place where include module being synchronously loaded in the requires
list.
解决这些警告的正确方法是什么?自动方法是否存在?
What is the right way to go around correcting these warnings? Does an automated way to do this exist?
P.S.现在唯一的方法就是在调试点处设置引发警告的位置,并追溯到导致警告生成的文件所在的行.
P.S. The only way to do this right now, is to set a debug point where the warning is raised, and trace back to which line in which file is leading to the warning being generated.
推荐答案
在chrome中,在您的stacktrace中,(我认为Firefox现在也可以进行stacktrace吗?)在模块中调用的文件通常是(总是?)不是全部文件的第一个文件.
In chrome, in your stacktrace, (I think Firefox does stacktraces as well nowadays?) the file that is calling in a module is usually (always?) the 1st file that is not ext-all.
Ext.require
是用于自动执行内容(例如js-minification)的操作,因此您无法真正实现自身的自动化.
Ext.require
is something used TO automate stuff ( eg js-minification) so you can't really automate it in and of itself.
当声明一个组件时(使用 Ext.define
或 Ext.create
),您应该指定Ext要用于该组件的组件的模块. Ext.require
(好吧,如果您希望至少摆脱此警告)
When you declare a component ( using Ext.define
or Ext.create
) you should be specifying the modules the component that Ext is going to use for the component with Ext.require
( well, if you want to get rid of this warning atleast )
您使用的每个自定义组件应或多或少遵循相同的想法:
Every custom component that you are using should more or less follow the same idea:
Ext.define('My.app.Panel', {
extend: 'Ext.panel.Panel', //
requires: [
'My.app.PanelPart2', //Hey! warning is gone!
'My.app.PanelPart3'
]
constructor: function (config) {
this.callParent(arguments);
//...
},
statics: {
method: function () {
return 'abc';
}
}
});
如果您不关心性能,而只想摆脱流浪警告(从技术上讲是疯狂的,则可以在加载程序配置中忽略错误消息.
And if you don't care about performance, and only want to get rid of stray warnings ( insanity technically, you can just muck your error message, in the loader config .
Ext.loader.setConfig({
enabled: true,
paths: {
'My': 'my_own_path'
},
onError:function(){}//or custom handler? :D
请参阅mitchsimeons答案: http://www.sencha.com/forum/showthread.php?178888-Tons-of-Synchronously-Loading-Warning-Messages
See mitchsimeons answer: http://www.sencha.com/forum/showthread.php?178888-Tons-of-Synchronously-Loading-Warning-Messages
以及有关为何要求的博客文章: http://www.sencha.com/blog/using-ext-loader-for-your-application
and a blog post on why requires: http://www.sencha.com/blog/using-ext-loader-for-your-application
这篇关于如何解决ExtJS"同步加载& quot;警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!