angularjs /渲染内联之间的性能差异或使用NG-包括 [英] angularjs / rendering Performance difference between inlining or using ng-include

查看:138
本文介绍了angularjs /渲染内联之间的性能差异或使用NG-包括的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以用NG-包括包括局部角度视图中还是可以使用服务器端的谐音做在服务器上。我在考虑使用服务器端的谐音,而不是棱角分明的谐音,然后NG-包括(与脚本标记),因为我读的地方,棱角分明的谐音创造新的范围,这可能会伤害在$消化性能。

I can use ng-include to include a partial inside an angular view or I can use server side partials to do it on the server. I'm thinking about using server side partials instead of angular partials and then ng-include (with the script tag) because I read somewhere that angular partials create new scopes and this can hurt performance on $digest.

有没有效力了这一点。什么是对性能的影响采用了棱角分明的时候包括

Is there any validity to this. What is the effect on performance when using angular includes

推荐答案

NG-包括将创建一个新的范围和注册表(在路径前$ P $在范围,其中 NG-包括使用pssion NG-包括被使用。虽然这招致一些额外的处理仍是基于JavaScript的对象,因此是非常快的。新手表外加范围的影响应该在大多数情况下,完全可以忽略不计。

ng-include will create a new scope and register a watch (on a path expression used by ng-include) on a scope where the ng-include is used. While this incurs some additional processing it is still JavaScript-objects based and as such is very fast. The effect of a new watch plus an additional scope should be totally negligible in most cases.

唯一的区别我可以看到的是, NG-包括将包括/过取谐音,当渲染部分异步,所以你可能会看到一个有点延迟,尤其是网络(但是这可以通过$ p $对装载的partials这里描述来缓解:<一href=\"http://stackoverflow.com/a/12346901/1418796\">http://stackoverflow.com/a/12346901/1418796)

The only real difference I can see is that ng-include will include / render your partial asynchronously, so you might see a bit of delay, especially when fetching partials over the network (but this can be mitigated by pre-loading partials as described here: http://stackoverflow.com/a/12346901/1418796)

在短:在大多数情况下的效果 NG-包括如果谐音是pre装可以忽略不计

In short: in most cases the effect of ng-include should be negligible if partials are pre-loaded.

最后一个评论: premature优化是一切罪恶的根。直到你测量的的应用程序的性能,并确定不要启动MICR性能调整, NG-包括是一个瓶颈。

One last comment: "premature optimization is the root of all evil". Don't start micr-performance adjustments until you measure performance of your application and determine that ng-include is a bottleneck.

这篇关于angularjs /渲染内联之间的性能差异或使用NG-包括的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆