Best practices to manage clientlibs in AEM(Adobe CQ)
Hi,
I'm trying to get the best approaches to manage clientlibs in AEM. I have tried the following approaches:
Approach 1) Created component level client libs for each component under "/apps", included them in the component and a site level clientlibs which are common across all the pages of the site under "/etc/designs/" and included that in the headlibs of a base template.
This approach makes the code modular and easy to debug.
Drawback: The problem with the above approach is in the webserver "/apps" will be restricted and I'm getting "403 forbidden error" while accessing these component level clientlibs and also there will be multiple calls to get each component level client libs.
Approach 2) Created component level client libs for each component under "/apps", embeded them in site level client libs under "/etc/designs" and included this site level client lib in the headlibs of base template.
With this approach only one call will be made to get all the clientlibs.
Drawback: The problem with this approach is that all the component clientlibs are included in each and every page even though that particular component is not included in that page which makes the client libs redundant. If some js code is dependent on a component and if that component is not present in that page then it is throwing js errors.
Approach 3) Created component level client libs for each component under "/apps", embeded them in site level client libs under "/etc/designs" and included this site level client lib in the headlibs of base template. Now code in each js file of component client libs are written in a function and this js function is called from the component.
With this approach we can control the js errors as component js will be executed only when the component is included in the page.
Drawback: The problem here is we can't control the naming of those functions across all the components and the code will still be redundant.
Approach 4) Create client libs for each component under "/apps", now create client libs for each template and embed only those component level client libs in each template where these components are present.
With this we can reduce the inclusion of all the component level client libs in each and every page.
Drawback: The problem with this approach is we will have so many client libs under "/etc/designs" and if a component is included in multiple templates we need to embed those component level client libs in all the templtes. Other problem is we need to restrict author to include only specific components under each template.
Please check out above approaches and give feedback and suggest best practices to mange client libs in AEM.
-Thanks in advance