April 2, 2020
Estimated Post Reading Time ~

Manage clientLibs in AEM through ClientLibraryProxyServlet

AEM provides Client-side Library Folders to organize JavaScript and CSS resources and takes care of producing the correct links in your final webpage to load the correct code. Some of the commonly used approaches are

"Unify approach": Keep everything under /etc/designs/{project}/clientlibs
Modular approach: Creating component level clientlibs for each component under "/apps". The disadvantage of this approach
When the final webpage is rendered leads to increasing the number of calls as well as loading clientlibs throughout the page. Violation of web best practices that call for CSS to be loaded in the head and (in general) JS to be loaded just before the </body> tag. 

With AEM 5.5 onwards the ACLs were made more secure. Most notably, /apps & /libs were locked down in general. This leads to providing explicit ACL permissions for clientlibs and thereby you are exposing application structure.
Hybrid Approach: To get the benefit of a modular approach and to overcome disadvantages mentioned earlier, Make use of ClientLibraryProxyServlet to serve client libs hosted under /apps by using a trick of embedding all the clientlibs of /apps/*. The steps for the attached samples are
Create a new client library under /apps/... with a new category. Let's say myapp.all 

Add an embed property and include all modular component library. (firstcomp,secondcomp)
Add boolean allowProxy = 'true'
On the headlibs.jsp include the above <cq:includeClientLib categories="myapp.all"/>
Then the clientlib will then be proxied via <script type="text/javascript" src="/etc.clientlibs/myapp/clientlibs/all.js"></script> there bypassing access control set on the clientlib.


Lastly, configure dispatcher.any to allow for /etc.clientlibs/<app>

Note: CQ5.5 does not have ClientLibraryProxyServlet as a workaround create a clientlibs directly under /etc/designs and embed all your modular component clientlibs category from apps/*.

Reference: http://dev.day.com/docs/en/cq/current/developing/clientlibs.html


By aem4beginner

No comments:

Post a Comment

If you have any doubts or questions, please let us know.