Last active
August 29, 2015 14:01
-
-
Save sorenlouv/abc62b1430d06f5c54ee to your computer and use it in GitHub Desktop.
Performance bookmarklet for Angularjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var bindings = document.getElementsByClassName('ng-binding').length; | |
var scopes = document.getElementsByClassName('ng-scope').length; | |
var bodyScope = angular.element(document.querySelector('body')).scope(); | |
var watchers = bodyScope && bodyScope.$$watchers ? bodyScope.$$watchers.length : '?'; | |
var getWatchers = function () { | |
var root = document.getElementsByTagName('body')[0]; | |
var numberOfWatches = 0; | |
var f = function (element) { | |
var $element = angular.element(element); | |
var watchers = $element.scope().$$watchers; | |
if(watchers){ | |
numberOfWatches += watchers.length; | |
} | |
angular.forEach($element.children(), function (childElement) { | |
f(childElement); | |
}); | |
}; | |
f(root); | |
return numberOfWatches; | |
}; | |
console.log('Bindings: ', bindings); | |
console.log('Scopes: ', scopes); | |
console.log('Watchers (Body): ', watchers); | |
//console.log('Watchers (Entire page): ', getWatchers()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment