Friday, November 28, 2014

Angular.js performance tip: Disabling Debug Data

While reading through the Angular.js documentation I stumbled over the following great performance tip:
By default AngularJS attaches information about scopes to DOM nodes, and adds CSS classes to data-bound elements. The information that is not included is:
As a result of ngBind, ngBindHtml or {{...}} interpolations, binding data and CSS class ng-class is attached to the corresponding element.
Where the compiler has created a new scope, the scope and either ng-scope or ng-isolated-scope CSS class are attached to the corresponding element. These scope references can then be accessed via element.scope() and element.isolateScope().
Tools like Protractor and Batarang need this information to run, but you can disable this in production for a significant performance boost with:
myApp.config(['$compileProvider', function ($compileProvider) {
$compileProvider.debugInfoEnabled(false);
}]);
If you wish to debug an application with this information then you should open up a debug console in the browser then call this method directly in this console:
angular.reloadWithDebugInfo();
The page should reload and the debug information should now be available.

For more see the docs pages on $compileProvider and angular.reloadWithDebugInfo.
Nice! Glimlach