exiadbq exiadbq - 1 month ago 19
AngularJS Question

$TemplateCache or TemplateUrl for directive

I have $http.get all the html templates into the $TemplateCache, my question is for my directives is it more efficient to use

TemplateUrl : abc.html


or

Template : $TemplateCache.get('abc.html')?

Answer

templateUrl will request the html for the first time and will put it in templateCache, so only the first time you will have the hit to the server and NOT for each time.

templateCache would avoid that hit even for the first time.

you can use this grunt to put all your templates at once in the template cache, to avoid hitting server for each template. This would make it much more efficient.