Blog post banner for improve angularjs performance

In the recent years, the use of AngularJS has increased drastically because of its varied features. However, complaints about AngularJS applications have also seen a rise. So how to address the issues like initial load time, user command responsiveness, etc.? Following some essential tips would be really helpful.

Tips to better the performance of AngularJS

Avoiding watchers:

When an AngularJS developer uses too many watchers, it can make the Angular app slow. Dirty checking is used for maintaining a track of the changes made in the app. So every watcher has to be gone through to check if any updation is required. AngularJS will need to re-run the digest cycle once more if one of the watcher is depended upon by an additional watcher. This will continue to happen till all the watchers are updated and that the app is stabilized.

Reduce or avoid using ng-repeat

ng-repeat creates poor performance. With 2000-2500 two-way bindings to watch, AngularJS gets slower. But if you still have to use it, then go for pagination or scrolling.

Use $watchCollection

Rather than using $watch with a 3rd parameter, use $watchCollection. If it is 2 parameters, $watch is fast. Though $watchCollection more or less acts like $watch, it checks just the first layer. Thus, the performance can be improved.

Backbench the functions using console.time

console.time, which is a wonderful API, is very helpful, especially when debugging issues. Also, it is preferable to use console.time call to profile, which required only a few variables. Additionally, sub-millisecond resolution is also provided.

Benchmark your watchers using Batarang

Batarang is really an awesome tool. It is very helpful in debugging Angular apps. Lots of highly features are offered in Batarang. Using it, addressing performance bottlenecks would be very easier.

Final words: 

Developing AngularJS apps would be easier and the performance can be greatly improved by following some useful tips. Some other tips for improving Angular performance include the use of Bind, avoiding repeated filters, debouncing ng-model and using Lodash.