1

If we give cq:includeClientLib inside my component jsp and if we drag and drop the component twice on that page, will the clientlib gets loaded/included twice?

what will be the case if we do in Sightly way (data-sly-call="${clientlib.all @ categories='somecategory'}") ?

And also what is the suggested method of including client libs, either create a clientlib specific to the component and load only for that component or include all the CSS and JS at a common clientlib and use it across?

Sai
  • 25
  • 9

2 Answers2

2

No, the clientlib is only included once for a category.

This is by design as the HTL (and respective JSP tag) are evaluated during runtime and the processor keeps a map of categories that have already been included and does not include them again.

Imran Saeed
  • 3,414
  • 1
  • 16
  • 27
  • Thanks! this is not the same in HTML right? including two script/style tags duplicate the styles. – Sai Jul 19 '17 at 05:10
2

As @i.net mentioned, each category will only be included once. To answer your follow up question about the suggested method..

The best practice seems to be to define a client library for each component, which is then embedded into a "global" client library. That global client library will then be included within your page template.

/etc/designs/acme/clientlibs-all
    categories=["acme-all"]
    embed=[compA,compB]
/apps/acme/components/compA/clientlibs
    categories=["compA"]
/apps/acme/components/compB/clientlibs
    categories=["compB"]

The reason the global client library is located under /etc/designs is to prevent exposing /apps to the public. However, in AEM 6.3, you could make use of the allowProxy property to serve the code at /etc.designs/. This would then look like this:

/apps/acme/clientlibs/clientlibs-all
    categories=["acme-all"]
    embed=[compA,compB]
    allowProxy=true
/apps/acme/components/compA/clientlibs
    categories=["compA"]
/apps/acme/components/compB/clientlibs
    categories=["compB"]

Adobe recently released a good tutorial of more recent best practices around client library structure: https://helpx.adobe.com/experience-manager/kt/sites/using/getting-started-wknd-tutorial-develop/part3.html

mickleroy
  • 998
  • 5
  • 8