问题
During the debugging of my angularjs application, I found a lot of parse html events in the dev tools.
The timeline says that this event is invoked by jQuery.extend.buildFragment
and it's hard for me to understand, what directive invokes parse html.
How can I detect, what exactly causes parse html events? Probably the reason could be in the ng-repeat
, but I'm not sure.
These events slow down $scope.$apply
as well.
回答1:
Every partial html in angular will trigger Parse HTML event, like ng-includes, ng-repeats, directives, and $digest cycles.
Also using jQuery will give you a lot of overhead for initalize jquery instances. jQuery or jQlite buildFragment is called when you or directives or angular call element.html('something tags'), which in turn write to innerHTML which cause parse HTML event in browser and angular walk those children to find more directives and compile those until its complete.
To minimize those, you need to batch process those, but nature of angular will be hard to do directly. May be you can try to use one-time binding syntax :: in angular 1.3+ or make less watchers, so angular won't have to parse html again and again.
来源:https://stackoverflow.com/questions/31697644/angularjs-parse-html-events-in-timeline