SlideShare a Scribd company logo
AEM Client
Libraries
www.tothenew.com
Agenda
• What is clientlib & Why do we need it?
• Pre-requisite for AEM ClientLib
• How Client-Side libraries works in AEM?
• Dependency Vs Embed
• Debugging Tools
• AEM Design & Theme
• ClientLib configuration : minification
• Best Practices for ClientLib
www.tothenew.com
What is clientlib & Why do we need it?
• Modern websites rely heavily on client-side processing driven by complex JavaScript and CSS code.
Organizing and optimizing the serving of this code can be a complicated issue.
• Standard Way of including Client Library (JS/CSS):
<script type="text/javascript" src="../jquery/source/1.8.1/jquery-1.8.1.js"></script>
While this approach works in AEM, there is the danger that multiple copies of the same JS library may be
included in the final HTML output.
• To avoid this and to allow logical organization of client-side libraries AEM uses client-side library folders.
www.tothenew.com
Pre-requisite for AEM ClientLib
• A client-side library folder is a repository node of type cq:ClientLibraryFolder, placed anywhere within the
/apps, /libs and /etc
[cq:ClientLibraryFolder] > sling:Folder
- dependencies (string) multiple
- categories (string) multiple
- embed (string) multiple
• categories: Identifies the categories into which the set of JS and/or CSS files within this cq:ClientLibraryFolder fall.
The categories property, being multi-valued, allows a library folder to be part of more than one category.
• dependencies: This is a list of other client library categories on which this library folder depends. For example, given
two cq:ClientLibraryFolder nodes F and G, if a file in F requires another file in G in order to function properly, then at
least one of the categories of G should be among the dependencies of F.
• embed: Used to embed code from other libraries. If node F embeds nodes G and H, the resulting HTML will be a
concentration of content from nodes G and H.
www.tothenew.com
How Client-side Libraries works in AEM?
• Add a cq:includeClientLib tag to your JSP code to add a link to client libraries in the generated HTML page. To
reference the libraries, you use the value of the categories property of the cq:ClientLibrary node.
<cq:includeClientLib categories="cq.jquery"/> // To include both CSS and JS libraries
<cq:includeClientLib js="cq.jquery"/>
<cq:includeClientLib css="cq.jquery"/>
The generated HTML page contains the following code:
<script type="text/javascript"
src="/etc/clientlibs/foundation/cq.jquery.js"></script>
• The node contains :
– One or more source files that, at runtime, are merged into a single JS and/or CSS file. The name of the generated file is the node
name with either the .js or .css file name extension. For example, cq.jquery.js or cq.jquery.css.
– Resources that support CSS styles, such as image files.
– One js.txt file and/or one css.txt file that identifies the source files to merge in the generated JS and/or CSS files.
• #base=[root] , where [root] is the name of the root folder where all scripts are present, like ., js, css.
• The web client must have permissions to access the cq:ClientLibraryFolder node. Generally, you locate the node
below /etc/clientlibs in the repository
www.tothenew.com
Dependency Vs Embed
Dependency: When the code in your client library folder references other libraries.
• In the JSP, the cq:includeClientLib causes the HTML code to include a link to your generated library file as
well as the dependencies.
<script src="/etc/clientlibs/foundation/cq.jquery.js" type="text/javascript">
<script src="/etc/clientlibs/mylibs/publicmain.js" type="text/javascript">
• The dependencies must be another cq:ClientLibraryFolder. To identify dependencies, add a property to your
cq:ClientLibraryFolder node with the following attributes:
– Name: dependencies
– Type: String[]
– Values: The value of the categories property of the cq:ClientLibraryFolder node that the current library folder depends
on.
• Disadvantage: A new request is made to the server for every dependency.
www.tothenew.com
Dependency Vs Embed
Embed: You can embed code from a client library into another client library.
• At runtime, the generated JS and CSS files of the embedding library includes the code of the embedded
library.
• Embedding code is useful for providing access to libraries that are stored in secured areas of the repository.
• App-specific client library folders:
It is a best practice to keep all application-related files in their application folder below /app.
It is also a best practice to deny access for web site visitors to the /app folder.
To satisfy both best practices, create a client library folder below the/etc folder that embeds the client library
that is below /app.
• Using embedding helps to minimize requests
Q: How many requests are made when you embed a clientLib which itself has one dependency?
www.tothenew.com
Debugging Tools
• To trace the origin of embedded code :
?debugClientLibs=true
• Discover client libraries :
libs/granite/ui/content/dumplibs.test.html
• Rebuild clientlibs :
libs/granite/ui/content/dumplibs.rebuild.html
www.tothenew.com
AEM Design & Theme
The <cq:includeClientLib> tag Includes a AEM html client library, which can be a js, a css or a theme library
theme:
A list of comma-separated client lib categories. This will include all theme related libraries (both CSS and JS) for the
given categories.
themed
A flag that indicates of only themed or non-themed libraries should be included. If omitted, both sets are included.
geometrixx-clientlibs
themes
myTheme (clientLibray)
css.txt
myCss.css
js.txt
myJS.js
www.tothenew.com
ClientLib configuration : minification
When it comes to the production environment, page load performance is of the utmost importance. The more files
that need to be fetched and the greater their size, the longer it will take for the page to be loaded.
AEM can deliver enhanced performance by enabling Minify in the Day CQ HTML Library Manager of the Felix
Configuration console.
• Minify compresses JS and CSS using the YUI compressor, removing all comments and whitespace.
www.tothenew.com
Best Practices for clientLib
• Place component JS and CSS in a clientlib located in the component folder - /apps/sample-
component/clientlibs.
• Embed component clientlibs into a single clientlib to reduce requests.
• Request all clientlibs from /etc, avoid pointing to apps.
• Use the dependencies property of a clientlib to define dependencies between libraries.
• Do minification of client libraries on the publish instance.
• Don’t include JS & CSS directly at the component unless it is very important.
JS & CSS CODING GUIDELINES:
www.tothenew.com
Assignments
• Problem-1
– Create a component with a dialog and having color drop down (green, blue, black
etc) and one rich text editor for authoring text.
– This component is supposed to render text and apply chosen color to text.
• Problem-2
– Create two designs which will have different text color & background theme.
– Apply both of them in different pages.
– The component text & background color should reflect based on the design
applied.
www.tothenew.com
References
• https://docs.adobe.com/docs/en/cq/5-6-1/developing/clientlibs.html
• https://docs.adobe.com/docs/en/aem/6-0/develop/mobile/responsive.html
• https://docs.adobe.com/docs/en/aem/6-1/develop/the-basics/clientlibs.html
AEM - Client Libraries

More Related Content

PPTX
Introduction to Sightly and Sling Models
PDF
Understanding Sling Models in AEM
PDF
AEM Sightly Template Language
PPTX
AEM and Sling
PDF
Aem dispatcher – tips & tricks
PPTX
HTL(Sightly) - All you need to know
PDF
AEM Sightly Deep Dive
PDF
JCR, Sling or AEM? Which API should I use and when?
Introduction to Sightly and Sling Models
Understanding Sling Models in AEM
AEM Sightly Template Language
AEM and Sling
Aem dispatcher – tips & tricks
HTL(Sightly) - All you need to know
AEM Sightly Deep Dive
JCR, Sling or AEM? Which API should I use and when?

What's hot (20)

PPTX
PPTX
Heap Dump Analysis - AEM: Real World Issues
PDF
AEM Best Practices for Component Development
PPTX
AEM Rich Text Editor (RTE) Deep Dive
PPTX
Javascript best practices
PPTX
Sling Models Overview
PDF
Basics of Solr and Solr Integration with AEM6
PPTX
Spring Framework
PPT
JavaScript & Dom Manipulation
PDF
A story of the passive aggressive sysadmin of AEM
PPTX
Sightly - Part 2
PDF
Spring Framework - Spring Security
PDF
Introduction to Sightly
PDF
Spring Framework - MVC
PDF
PUC SE Day 2019 - SpringBoot
PDF
Angular
PPTX
Object Oriented Programming In JavaScript
KEY
JSON-LD: JSON for Linked Data
PDF
Angular material
PPTX
BlueHat v17 || Dangerous Contents - Securing .Net Deserialization
Heap Dump Analysis - AEM: Real World Issues
AEM Best Practices for Component Development
AEM Rich Text Editor (RTE) Deep Dive
Javascript best practices
Sling Models Overview
Basics of Solr and Solr Integration with AEM6
Spring Framework
JavaScript & Dom Manipulation
A story of the passive aggressive sysadmin of AEM
Sightly - Part 2
Spring Framework - Spring Security
Introduction to Sightly
Spring Framework - MVC
PUC SE Day 2019 - SpringBoot
Angular
Object Oriented Programming In JavaScript
JSON-LD: JSON for Linked Data
Angular material
BlueHat v17 || Dangerous Contents - Securing .Net Deserialization
Ad

Viewers also liked (19)

PDF
CIRCUIT 2015 - UI Customization in AEM 6.1
PDF
User Interface customization for AEM 6
PDF
(Re)discover your AEM
PDF
REST in AEM
PDF
CIRCUIT 2015 - AEM Infrastructure Automation with Chef Cookbooks
PPTX
AEM 6 - Client Context Personalization
PDF
Master Chef class: learn how to quickly cook delightful CQ/AEM infrastructures
PDF
CIRCUIT 2015 - Content API's For AEM Sites
PPTX
When dispatcher caching is not enough...
PPTX
AEM 6.0 Touch-optimized UI
PDF
PDF
Introducing Apache Jackrabbit OAK
PPTX
AEM 6.0 - Author UI Customization & Features
PPTX
SQFI 26 August 2010
PDF
Dandelion Statement of Qualifications 2
PDF
Cosmic equipments-india-pvt-ltd
PDF
When dispatcher caching is not enough... (extended version)
PDF
Aem authentication vs idp
PDF
Subsystems: For those occasions where bundles are just too small... - Graham ...
CIRCUIT 2015 - UI Customization in AEM 6.1
User Interface customization for AEM 6
(Re)discover your AEM
REST in AEM
CIRCUIT 2015 - AEM Infrastructure Automation with Chef Cookbooks
AEM 6 - Client Context Personalization
Master Chef class: learn how to quickly cook delightful CQ/AEM infrastructures
CIRCUIT 2015 - Content API's For AEM Sites
When dispatcher caching is not enough...
AEM 6.0 Touch-optimized UI
Introducing Apache Jackrabbit OAK
AEM 6.0 - Author UI Customization & Features
SQFI 26 August 2010
Dandelion Statement of Qualifications 2
Cosmic equipments-india-pvt-ltd
When dispatcher caching is not enough... (extended version)
Aem authentication vs idp
Subsystems: For those occasions where bundles are just too small... - Graham ...
Ad

Recently uploaded (20)

PPTX
CHAPTER 2 - PM Management and IT Context
PDF
Tally Prime Crack Download New Version 5.1 [2025] (License Key Free
PDF
Designing Intelligence for the Shop Floor.pdf
PDF
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
PDF
AutoCAD Professional Crack 2025 With License Key
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PPTX
Weekly report ppt - harsh dattuprasad patel.pptx
PPTX
history of c programming in notes for students .pptx
PPTX
Operating system designcfffgfgggggggvggggggggg
PDF
iTop VPN Free 5.6.0.5262 Crack latest version 2025
PDF
CapCut Video Editor 6.8.1 Crack for PC Latest Download (Fully Activated) 2025
PDF
Autodesk AutoCAD Crack Free Download 2025
PPTX
Oracle Fusion HCM Cloud Demo for Beginners
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PPTX
Monitoring Stack: Grafana, Loki & Promtail
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PPTX
assetexplorer- product-overview - presentation
PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PPTX
Patient Appointment Booking in Odoo with online payment
CHAPTER 2 - PM Management and IT Context
Tally Prime Crack Download New Version 5.1 [2025] (License Key Free
Designing Intelligence for the Shop Floor.pdf
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
AutoCAD Professional Crack 2025 With License Key
Adobe Illustrator 28.6 Crack My Vision of Vector Design
Weekly report ppt - harsh dattuprasad patel.pptx
history of c programming in notes for students .pptx
Operating system designcfffgfgggggggvggggggggg
iTop VPN Free 5.6.0.5262 Crack latest version 2025
CapCut Video Editor 6.8.1 Crack for PC Latest Download (Fully Activated) 2025
Autodesk AutoCAD Crack Free Download 2025
Oracle Fusion HCM Cloud Demo for Beginners
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
Design an Analysis of Algorithms I-SECS-1021-03
Monitoring Stack: Grafana, Loki & Promtail
Wondershare Filmora 15 Crack With Activation Key [2025
assetexplorer- product-overview - presentation
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
Patient Appointment Booking in Odoo with online payment

AEM - Client Libraries

  • 2. www.tothenew.com Agenda • What is clientlib & Why do we need it? • Pre-requisite for AEM ClientLib • How Client-Side libraries works in AEM? • Dependency Vs Embed • Debugging Tools • AEM Design & Theme • ClientLib configuration : minification • Best Practices for ClientLib
  • 3. www.tothenew.com What is clientlib & Why do we need it? • Modern websites rely heavily on client-side processing driven by complex JavaScript and CSS code. Organizing and optimizing the serving of this code can be a complicated issue. • Standard Way of including Client Library (JS/CSS): <script type="text/javascript" src="../jquery/source/1.8.1/jquery-1.8.1.js"></script> While this approach works in AEM, there is the danger that multiple copies of the same JS library may be included in the final HTML output. • To avoid this and to allow logical organization of client-side libraries AEM uses client-side library folders.
  • 4. www.tothenew.com Pre-requisite for AEM ClientLib • A client-side library folder is a repository node of type cq:ClientLibraryFolder, placed anywhere within the /apps, /libs and /etc [cq:ClientLibraryFolder] > sling:Folder - dependencies (string) multiple - categories (string) multiple - embed (string) multiple • categories: Identifies the categories into which the set of JS and/or CSS files within this cq:ClientLibraryFolder fall. The categories property, being multi-valued, allows a library folder to be part of more than one category. • dependencies: This is a list of other client library categories on which this library folder depends. For example, given two cq:ClientLibraryFolder nodes F and G, if a file in F requires another file in G in order to function properly, then at least one of the categories of G should be among the dependencies of F. • embed: Used to embed code from other libraries. If node F embeds nodes G and H, the resulting HTML will be a concentration of content from nodes G and H.
  • 5. www.tothenew.com How Client-side Libraries works in AEM? • Add a cq:includeClientLib tag to your JSP code to add a link to client libraries in the generated HTML page. To reference the libraries, you use the value of the categories property of the cq:ClientLibrary node. <cq:includeClientLib categories="cq.jquery"/> // To include both CSS and JS libraries <cq:includeClientLib js="cq.jquery"/> <cq:includeClientLib css="cq.jquery"/> The generated HTML page contains the following code: <script type="text/javascript" src="/etc/clientlibs/foundation/cq.jquery.js"></script> • The node contains : – One or more source files that, at runtime, are merged into a single JS and/or CSS file. The name of the generated file is the node name with either the .js or .css file name extension. For example, cq.jquery.js or cq.jquery.css. – Resources that support CSS styles, such as image files. – One js.txt file and/or one css.txt file that identifies the source files to merge in the generated JS and/or CSS files. • #base=[root] , where [root] is the name of the root folder where all scripts are present, like ., js, css. • The web client must have permissions to access the cq:ClientLibraryFolder node. Generally, you locate the node below /etc/clientlibs in the repository
  • 6. www.tothenew.com Dependency Vs Embed Dependency: When the code in your client library folder references other libraries. • In the JSP, the cq:includeClientLib causes the HTML code to include a link to your generated library file as well as the dependencies. <script src="/etc/clientlibs/foundation/cq.jquery.js" type="text/javascript"> <script src="/etc/clientlibs/mylibs/publicmain.js" type="text/javascript"> • The dependencies must be another cq:ClientLibraryFolder. To identify dependencies, add a property to your cq:ClientLibraryFolder node with the following attributes: – Name: dependencies – Type: String[] – Values: The value of the categories property of the cq:ClientLibraryFolder node that the current library folder depends on. • Disadvantage: A new request is made to the server for every dependency.
  • 7. www.tothenew.com Dependency Vs Embed Embed: You can embed code from a client library into another client library. • At runtime, the generated JS and CSS files of the embedding library includes the code of the embedded library. • Embedding code is useful for providing access to libraries that are stored in secured areas of the repository. • App-specific client library folders: It is a best practice to keep all application-related files in their application folder below /app. It is also a best practice to deny access for web site visitors to the /app folder. To satisfy both best practices, create a client library folder below the/etc folder that embeds the client library that is below /app. • Using embedding helps to minimize requests Q: How many requests are made when you embed a clientLib which itself has one dependency?
  • 8. www.tothenew.com Debugging Tools • To trace the origin of embedded code : ?debugClientLibs=true • Discover client libraries : libs/granite/ui/content/dumplibs.test.html • Rebuild clientlibs : libs/granite/ui/content/dumplibs.rebuild.html
  • 9. www.tothenew.com AEM Design & Theme The <cq:includeClientLib> tag Includes a AEM html client library, which can be a js, a css or a theme library theme: A list of comma-separated client lib categories. This will include all theme related libraries (both CSS and JS) for the given categories. themed A flag that indicates of only themed or non-themed libraries should be included. If omitted, both sets are included. geometrixx-clientlibs themes myTheme (clientLibray) css.txt myCss.css js.txt myJS.js
  • 10. www.tothenew.com ClientLib configuration : minification When it comes to the production environment, page load performance is of the utmost importance. The more files that need to be fetched and the greater their size, the longer it will take for the page to be loaded. AEM can deliver enhanced performance by enabling Minify in the Day CQ HTML Library Manager of the Felix Configuration console. • Minify compresses JS and CSS using the YUI compressor, removing all comments and whitespace.
  • 11. www.tothenew.com Best Practices for clientLib • Place component JS and CSS in a clientlib located in the component folder - /apps/sample- component/clientlibs. • Embed component clientlibs into a single clientlib to reduce requests. • Request all clientlibs from /etc, avoid pointing to apps. • Use the dependencies property of a clientlib to define dependencies between libraries. • Do minification of client libraries on the publish instance. • Don’t include JS & CSS directly at the component unless it is very important. JS & CSS CODING GUIDELINES:
  • 12. www.tothenew.com Assignments • Problem-1 – Create a component with a dialog and having color drop down (green, blue, black etc) and one rich text editor for authoring text. – This component is supposed to render text and apply chosen color to text. • Problem-2 – Create two designs which will have different text color & background theme. – Apply both of them in different pages. – The component text & background color should reflect based on the design applied.