Should I minimize the use of angularjs' directives? -
Should I minimize the use of angularjs' directives? -
angularjs' directives awesome since each of them makes request, i'm wondering if it'd improve minimize utilize of it?
let's imagine have that:
<hero></hero> <slideshow></slideshow> <section> <sidebar></sidebar> <blog-articles></blog-articles> <rss-feed></rss-feed> <socials></socials> </section> in illustration i'm making 6 differents requests. isn't slowing downwards whole application? , if controllers dyanmically loaded, adding 6+ more files?
to create clearer, below how define directives.
angular.module( 'module', [] ) .directive( 'hero', function () { homecoming { restrict: 'e', templateurl: 'hero.html' }; } ) .directive( 'slideshow', function () { homecoming { restrict: 'e', templateurl: 'slideshow.html' }; } ) .directive( 'sidebar', function () { homecoming { restrict: 'e', templateurl: 'sidebar.html' }; } ) .directive( 'blogarticles', function () { homecoming { restrict: 'e', templateurl: 'blog-articles.html' }; } ) .directive( 'rssfeed', function () { homecoming { restrict: 'e', templateurl: 'rss-feed.html' }; } ) .directive( 'socials', function () { homecoming { restrict: 'e', templateurl: 'socials.html' }; } ); given illustration each directives makes ajax phone call load proper html file. maybe there's way minimize calls?
i think misusing directives here.. simple ng-include plenty template inclusion.
from angularjs docs:
at high level, directives markers on dom element (such attribute, element name, comment or css class) tell angularjs's html compiler ($compile) attach specified behavior dom element or transform dom element , children.
so directives used custom elements handling, not template inclusion (though it's possible so).
either way, if using ng-include or custom directive, requests made files. bad? probably.. think should leave plain html isn't changing in 1 file. dynamic page parts consider using ngroute or ui-router.
angularjs angularjs-directive request
Comments
Post a Comment