require.js 获取/加载顺序调试
是否有工具或 require.js 函数可以用来确定模块/传统脚本的获取和加载顺序?
例如,
a.js:
define(['b', 'c'], function(b,c){});
b.js:
define(['d'], function(d){});
然后是一个 main.js
require(['a'], function(a){});
我的假设是:
- a.js 将首先被获取
- b.js 和 c.js 将被第二次获取
- d.js 将最后被获取
并且模块将按照 d ->; 的顺序加载。 b-> c->一个。或者也许,d 和 c 同时存在(因为 c 没有像 d 那样的依赖关系),然后是 b,最后是 a。
然而,我从来都不能 100% 确定我的假设是正确的。我可以刷新页面 100 次并验证没有错误,但我仍然担心第 101 次尝试会失败。
AMD模块开发者,你们如何调试这个?
Is there a tool or require.js function I can use to determine the fetching and loading order of my modules/traditional scripts?
For example,
a.js:
define(['b', 'c'], function(b,c){});
b.js:
define(['d'], function(d){});
and then a main.js that has
require(['a'], function(a){});
My assumption here is that:
- a.js will be fetched first
- b.js and c.js will be fetched second
- d.js will be fetched last
and the modules will be loaded in the order of d -> b -> c -> a. Or perhaps, d and c at the same time (since c has no dependencies like d) then b and finally a.
However, I'm never 100% certain my assumptions are correct. I can refresh the page 100 times and verify I get no error, but I'm still paranoid that the 101st try will break.
AMD module developers, how do you debug this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为了精细控制模块的获取顺序,可以使用顺序插件。
您还可以在 Chrome/Firebug 等中打开网络控制台来查看提取的情况。
但是,您的示例是一个相当简单的示例,在第 101 次迭代或第 1001 次迭代中应该没有问题。我没有看到任何需要担心或需要调试的事情。
For fine control over the fetching order of modules, there's the order plugin.
You can also open the network console in Chrome/Firebug etc. to see the fetches take place.
But, your example is a fairly straightforward one that should have no problems either in the 101st iteration or the 1001st. I don't see anything to be concerned about or that needs debugging.