Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

angularjs / rendering Performance difference between inlining or using ng-include

I can use ng-include to include a partial inside an angular view or I can use server side partials to do it on the server. I'm thinking about using server side partials instead of angular partials and then ng-include (with the script tag) because I read somewhere that angular partials create new scopes and this can hurt performance on $digest.

Is there any validity to this. What is the effect on performance when using angular includes

like image 623
Harry Avatar asked May 18 '13 07:05

Harry


1 Answers

ng-include will create a new scope and register a watch (on a path expression used by ng-include) on a scope where the ng-include is used. While this incurs some additional processing it is still JavaScript-objects based and as such is very fast. The effect of a new watch plus an additional scope should be totally negligible in most cases.

The only real difference I can see is that ng-include will include / render your partial asynchronously, so you might see a bit of delay, especially when fetching partials over the network (but this can be mitigated by pre-loading partials as described here: https://stackoverflow.com/a/12346901/1418796)

In short: in most cases the effect of ng-include should be negligible if partials are pre-loaded.

One last comment: "premature optimization is the root of all evil". Don't start micr-performance adjustments until you measure performance of your application and determine that ng-include is a bottleneck.

like image 60
pkozlowski.opensource Avatar answered Oct 22 '22 08:10

pkozlowski.opensource