Skip to content

Instantly share code, notes, and snippets.

@Narayon
Created April 22, 2016 19:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Narayon/5f2cbb34594665abf3c81cc56eb7eed4 to your computer and use it in GitHub Desktop.
Save Narayon/5f2cbb34594665abf3c81cc56eb7eed4 to your computer and use it in GitHub Desktop.
AngularJS 1.x Performance Tips
In general, keep the digest cycle slim, avoiding the creation of watchers, when possible.
Some tips:
- ng-bind instead of {{expressions}}
- use bind once: ng-bind="::expression" or {{::expression}}
- avoid ng-repeat, but if necessary, use track by ...
- use small directives, with new or nested scope, instead of a monolithic scope
- use local events and $digest/$apply(when needed), to prevent running the digest cycle globally, for every event
- use $digest instead of $apply, when changes only affect children
- don't use filters in the DOM, use pre filtered data instead
- don't use true/false DOM logic in the controller
- avoid Angular directives, use vanilla
- is faster to generate new DOM elements, then manipulating existing ones
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment