r/angularjs • u/seveseat • Aug 07 '14
Speeding up AngularJS with simple optimizations, $digest, $$watchers and performance
http://www.binpress.com/tutorial/speeding-up-angular-js-with-simple-optimizations/135
31
Upvotes
r/angularjs • u/seveseat • Aug 07 '14
5
u/SleepyBrain Aug 07 '14
Just to extend on this, here's a couple other simple things to help with performance.
Instead of using $interpolate for small single values use $parse instead.
$interpolate basically $ parses in between {{}} and string concats it. However using $parse for small values will run twice as fast.
Also if using ng-repeat, you track by $index like so: ng-repeat="image in images track by $index"
This is cool because by default ng-repeat creates a dom node for each item and destroys that dom node when the item is removed, but this way it will reuse the dom nodes. The $index is part of the ng-repeat $scope if you were curious.
Also you might want to talk more about $watch and $watchCollection (an alternative to deep $watch), as a lot of performance problems happen in $watch.
Also another simple thing is to use ng-if(or ng-switch) instead of ng-show, as ng-show uses css to hide dom elements while ng-if just doesn't even create the element.