是否隐藏DOM元素提高性能?元素、性能、DOM

2023-09-13 04:52:43 作者:戒爱ing

可以说我有一个包含无数的表单元素,它们都看着模型值的HTML DIV,如果我用NG-显示,NG-IF或NG-交换机上的分区隐藏它,从做会这个角度停止JS脏检查的表单元素,从而提高我的应用程序的性能?

Lets say I have an HTML div containing numerous form elements that are all watching model values, if I use ng-show, ng-if, or ng-switch on the div to hide it, will this stop angular JS from doing dirty checking on the form elements and thus improve the performance of my app?

我认为,如果绑定的元素不可见,那么就没有必要角度进行检查绑定到这些价值观。

I figure that if the bound elements are not visible then there's no need for angular to be checking the values bound to them.

推荐答案

NG-节目 NG-隐藏将只设置一个CSS 显示风格,依然会受理的绑定。 NG-开关,但是,将完全注释掉不适用的案件,这反过来又意味着绑定在那些的不可以处理。我同意,但是,与Edmondo1984的答复,我怀疑你应该在此基础上你的选择。不要重写 NG-节目译文] 因为这个NG-开关 ES!

ng-show and ng-hide will only set a CSS display style, and will still process the bindings. ng-switch, however, will completely comment out the cases that do not apply, which in turn means bindings in those are not processed. I agree, however, with Edmondo1984's reply, that I doubt you should base your choices on this. Do not rewrite your ng-shows as ng-switches because of this!

您可以使用Chrome扩展 Batarang ,性能验证这一点标签显示这手表是活动的。

You can verify this with the Chrome extension Batarang, the performance tab shows which watches are active.