Component based clientlibs AEM











up vote
0
down vote

favorite












Is it better to split up clientlibs by components if it means more calls to the server?



I.e. using



<%@taglib prefix="ui" uri="http://www.adobe.com/taglibs/granite/ui/1.0" %>
<ui:includeClientLib categories="mqd.component.accordion" />



in the <component>.jsp instead of compiling all the CSS in a single stylesheet.










share|improve this question


























    up vote
    0
    down vote

    favorite












    Is it better to split up clientlibs by components if it means more calls to the server?



    I.e. using



    <%@taglib prefix="ui" uri="http://www.adobe.com/taglibs/granite/ui/1.0" %>
    <ui:includeClientLib categories="mqd.component.accordion" />



    in the <component>.jsp instead of compiling all the CSS in a single stylesheet.










    share|improve this question
























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      Is it better to split up clientlibs by components if it means more calls to the server?



      I.e. using



      <%@taglib prefix="ui" uri="http://www.adobe.com/taglibs/granite/ui/1.0" %>
      <ui:includeClientLib categories="mqd.component.accordion" />



      in the <component>.jsp instead of compiling all the CSS in a single stylesheet.










      share|improve this question













      Is it better to split up clientlibs by components if it means more calls to the server?



      I.e. using



      <%@taglib prefix="ui" uri="http://www.adobe.com/taglibs/granite/ui/1.0" %>
      <ui:includeClientLib categories="mqd.component.accordion" />



      in the <component>.jsp instead of compiling all the CSS in a single stylesheet.







      javascript css performance aem client-library






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 12 at 17:52









      Arielle Adams

      153




      153
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote



          accepted










          From what I know, this is more of a decision based your use case, there is no one approach which fits all the scenarios -



          Loading CSS at component level



          When you load CSS at the component level, it is not available in the HEAD section when the page rendering process kicks off. It will only render your component CSS when it encounters it somewhere in the body tag.



          Conditionally loading CSS based on the component is not available by default, you would have to write custom logic to achieve this.
          From this post,




          One way to achieve this is to intercept that behaviour. Use a filter
          and buffer all data written to the output buffer in memory. Then you
          can render safely all components and if you encounter your special
          component you can set a flag in the request attributes. The filter can
          then check for these attributes, change the buffer accordingly and
          then send everything out. That approach is a bit risky, because it
          can consume a lot of memory. And it changes the rendering performance and behaviour of your page. But it might be worth a try.



          Also, with component level CSS, you would have to ensure the styles
          for a component don't affect styles for another component, i.e. you
          would have to use narrow selectors to do this and ensure you don't
          break anything else in the process.




          Also, with component level CSS, you would have to ensure the styles for a component don't affect styles for another component, i.e. you would have to use narrow selectors to do this and ensure you don't break anything else in the process.





          Other approaches



          Using page components - If you have a component which has a lot of styles and you don't want this to get loaded on every other page, you can look at using page components(different templates) to achieve this. Each page component can load a different group of clientslibs based on its use.



          Using deferred clientlibs - If your layout constantly changes and you’re worried about how big your clientlibs file has become, deferred clientlibs might be a better option. Example from the link listed below -



          … [Navigation component logic]

          <ici:js-defer>

          <cq:includeClientLib js=”icidigital.components.navigation”/>

          </ici:js-defer>

          [Navigation component end]

          … [Sitemap component logic]

          <ici:js-defer>

          <cq:includeClientLib js=”icidigital.components.siteMap”/>

          </ici:js-defer>

          [Sitemap component end]

          becomes…

          <div class=”footer” />

          <script type=”text/javascript” src=”path/to/programmatically/combined/deferred/clientlib.js”></script>

          </div>


          Whatever approach you take, ensure caching, page load times, maintenance, performance, etc are taken into account.





          Further read



          Best approaches to clientlibs in AEM



          CSS best practices in clientlibs






          share|improve this answer























          • Thank you for such a thorough and helpful answer!
            – Arielle Adams
            Nov 13 at 20:52











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














           

          draft saved


          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53267562%2fcomponent-based-clientlibs-aem%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          0
          down vote



          accepted










          From what I know, this is more of a decision based your use case, there is no one approach which fits all the scenarios -



          Loading CSS at component level



          When you load CSS at the component level, it is not available in the HEAD section when the page rendering process kicks off. It will only render your component CSS when it encounters it somewhere in the body tag.



          Conditionally loading CSS based on the component is not available by default, you would have to write custom logic to achieve this.
          From this post,




          One way to achieve this is to intercept that behaviour. Use a filter
          and buffer all data written to the output buffer in memory. Then you
          can render safely all components and if you encounter your special
          component you can set a flag in the request attributes. The filter can
          then check for these attributes, change the buffer accordingly and
          then send everything out. That approach is a bit risky, because it
          can consume a lot of memory. And it changes the rendering performance and behaviour of your page. But it might be worth a try.



          Also, with component level CSS, you would have to ensure the styles
          for a component don't affect styles for another component, i.e. you
          would have to use narrow selectors to do this and ensure you don't
          break anything else in the process.




          Also, with component level CSS, you would have to ensure the styles for a component don't affect styles for another component, i.e. you would have to use narrow selectors to do this and ensure you don't break anything else in the process.





          Other approaches



          Using page components - If you have a component which has a lot of styles and you don't want this to get loaded on every other page, you can look at using page components(different templates) to achieve this. Each page component can load a different group of clientslibs based on its use.



          Using deferred clientlibs - If your layout constantly changes and you’re worried about how big your clientlibs file has become, deferred clientlibs might be a better option. Example from the link listed below -



          … [Navigation component logic]

          <ici:js-defer>

          <cq:includeClientLib js=”icidigital.components.navigation”/>

          </ici:js-defer>

          [Navigation component end]

          … [Sitemap component logic]

          <ici:js-defer>

          <cq:includeClientLib js=”icidigital.components.siteMap”/>

          </ici:js-defer>

          [Sitemap component end]

          becomes…

          <div class=”footer” />

          <script type=”text/javascript” src=”path/to/programmatically/combined/deferred/clientlib.js”></script>

          </div>


          Whatever approach you take, ensure caching, page load times, maintenance, performance, etc are taken into account.





          Further read



          Best approaches to clientlibs in AEM



          CSS best practices in clientlibs






          share|improve this answer























          • Thank you for such a thorough and helpful answer!
            – Arielle Adams
            Nov 13 at 20:52















          up vote
          0
          down vote



          accepted










          From what I know, this is more of a decision based your use case, there is no one approach which fits all the scenarios -



          Loading CSS at component level



          When you load CSS at the component level, it is not available in the HEAD section when the page rendering process kicks off. It will only render your component CSS when it encounters it somewhere in the body tag.



          Conditionally loading CSS based on the component is not available by default, you would have to write custom logic to achieve this.
          From this post,




          One way to achieve this is to intercept that behaviour. Use a filter
          and buffer all data written to the output buffer in memory. Then you
          can render safely all components and if you encounter your special
          component you can set a flag in the request attributes. The filter can
          then check for these attributes, change the buffer accordingly and
          then send everything out. That approach is a bit risky, because it
          can consume a lot of memory. And it changes the rendering performance and behaviour of your page. But it might be worth a try.



          Also, with component level CSS, you would have to ensure the styles
          for a component don't affect styles for another component, i.e. you
          would have to use narrow selectors to do this and ensure you don't
          break anything else in the process.




          Also, with component level CSS, you would have to ensure the styles for a component don't affect styles for another component, i.e. you would have to use narrow selectors to do this and ensure you don't break anything else in the process.





          Other approaches



          Using page components - If you have a component which has a lot of styles and you don't want this to get loaded on every other page, you can look at using page components(different templates) to achieve this. Each page component can load a different group of clientslibs based on its use.



          Using deferred clientlibs - If your layout constantly changes and you’re worried about how big your clientlibs file has become, deferred clientlibs might be a better option. Example from the link listed below -



          … [Navigation component logic]

          <ici:js-defer>

          <cq:includeClientLib js=”icidigital.components.navigation”/>

          </ici:js-defer>

          [Navigation component end]

          … [Sitemap component logic]

          <ici:js-defer>

          <cq:includeClientLib js=”icidigital.components.siteMap”/>

          </ici:js-defer>

          [Sitemap component end]

          becomes…

          <div class=”footer” />

          <script type=”text/javascript” src=”path/to/programmatically/combined/deferred/clientlib.js”></script>

          </div>


          Whatever approach you take, ensure caching, page load times, maintenance, performance, etc are taken into account.





          Further read



          Best approaches to clientlibs in AEM



          CSS best practices in clientlibs






          share|improve this answer























          • Thank you for such a thorough and helpful answer!
            – Arielle Adams
            Nov 13 at 20:52













          up vote
          0
          down vote



          accepted







          up vote
          0
          down vote



          accepted






          From what I know, this is more of a decision based your use case, there is no one approach which fits all the scenarios -



          Loading CSS at component level



          When you load CSS at the component level, it is not available in the HEAD section when the page rendering process kicks off. It will only render your component CSS when it encounters it somewhere in the body tag.



          Conditionally loading CSS based on the component is not available by default, you would have to write custom logic to achieve this.
          From this post,




          One way to achieve this is to intercept that behaviour. Use a filter
          and buffer all data written to the output buffer in memory. Then you
          can render safely all components and if you encounter your special
          component you can set a flag in the request attributes. The filter can
          then check for these attributes, change the buffer accordingly and
          then send everything out. That approach is a bit risky, because it
          can consume a lot of memory. And it changes the rendering performance and behaviour of your page. But it might be worth a try.



          Also, with component level CSS, you would have to ensure the styles
          for a component don't affect styles for another component, i.e. you
          would have to use narrow selectors to do this and ensure you don't
          break anything else in the process.




          Also, with component level CSS, you would have to ensure the styles for a component don't affect styles for another component, i.e. you would have to use narrow selectors to do this and ensure you don't break anything else in the process.





          Other approaches



          Using page components - If you have a component which has a lot of styles and you don't want this to get loaded on every other page, you can look at using page components(different templates) to achieve this. Each page component can load a different group of clientslibs based on its use.



          Using deferred clientlibs - If your layout constantly changes and you’re worried about how big your clientlibs file has become, deferred clientlibs might be a better option. Example from the link listed below -



          … [Navigation component logic]

          <ici:js-defer>

          <cq:includeClientLib js=”icidigital.components.navigation”/>

          </ici:js-defer>

          [Navigation component end]

          … [Sitemap component logic]

          <ici:js-defer>

          <cq:includeClientLib js=”icidigital.components.siteMap”/>

          </ici:js-defer>

          [Sitemap component end]

          becomes…

          <div class=”footer” />

          <script type=”text/javascript” src=”path/to/programmatically/combined/deferred/clientlib.js”></script>

          </div>


          Whatever approach you take, ensure caching, page load times, maintenance, performance, etc are taken into account.





          Further read



          Best approaches to clientlibs in AEM



          CSS best practices in clientlibs






          share|improve this answer














          From what I know, this is more of a decision based your use case, there is no one approach which fits all the scenarios -



          Loading CSS at component level



          When you load CSS at the component level, it is not available in the HEAD section when the page rendering process kicks off. It will only render your component CSS when it encounters it somewhere in the body tag.



          Conditionally loading CSS based on the component is not available by default, you would have to write custom logic to achieve this.
          From this post,




          One way to achieve this is to intercept that behaviour. Use a filter
          and buffer all data written to the output buffer in memory. Then you
          can render safely all components and if you encounter your special
          component you can set a flag in the request attributes. The filter can
          then check for these attributes, change the buffer accordingly and
          then send everything out. That approach is a bit risky, because it
          can consume a lot of memory. And it changes the rendering performance and behaviour of your page. But it might be worth a try.



          Also, with component level CSS, you would have to ensure the styles
          for a component don't affect styles for another component, i.e. you
          would have to use narrow selectors to do this and ensure you don't
          break anything else in the process.




          Also, with component level CSS, you would have to ensure the styles for a component don't affect styles for another component, i.e. you would have to use narrow selectors to do this and ensure you don't break anything else in the process.





          Other approaches



          Using page components - If you have a component which has a lot of styles and you don't want this to get loaded on every other page, you can look at using page components(different templates) to achieve this. Each page component can load a different group of clientslibs based on its use.



          Using deferred clientlibs - If your layout constantly changes and you’re worried about how big your clientlibs file has become, deferred clientlibs might be a better option. Example from the link listed below -



          … [Navigation component logic]

          <ici:js-defer>

          <cq:includeClientLib js=”icidigital.components.navigation”/>

          </ici:js-defer>

          [Navigation component end]

          … [Sitemap component logic]

          <ici:js-defer>

          <cq:includeClientLib js=”icidigital.components.siteMap”/>

          </ici:js-defer>

          [Sitemap component end]

          becomes…

          <div class=”footer” />

          <script type=”text/javascript” src=”path/to/programmatically/combined/deferred/clientlib.js”></script>

          </div>


          Whatever approach you take, ensure caching, page load times, maintenance, performance, etc are taken into account.





          Further read



          Best approaches to clientlibs in AEM



          CSS best practices in clientlibs







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 13 at 5:49

























          answered Nov 13 at 0:38









          SubSul

          1,393618




          1,393618












          • Thank you for such a thorough and helpful answer!
            – Arielle Adams
            Nov 13 at 20:52


















          • Thank you for such a thorough and helpful answer!
            – Arielle Adams
            Nov 13 at 20:52
















          Thank you for such a thorough and helpful answer!
          – Arielle Adams
          Nov 13 at 20:52




          Thank you for such a thorough and helpful answer!
          – Arielle Adams
          Nov 13 at 20:52


















           

          draft saved


          draft discarded



















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53267562%2fcomponent-based-clientlibs-aem%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          How to send String Array data to Server using php in android

          Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents

          Is anime1.com a legal site for watching anime?