SlideShare a Scribd company logo
1 of 14
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

What's hot

Sling models by Justin Edelson
Sling models by Justin Edelson Sling models by Justin Edelson
Sling models by Justin Edelson
AEM HUB
 
Introduction to SASS
Introduction to SASSIntroduction to SASS
Introduction to SASS
Jon Dean
 
HTL(Sightly) - All you need to know
HTL(Sightly) - All you need to knowHTL(Sightly) - All you need to know
HTL(Sightly) - All you need to know
Prabhdeep Singh
 

What's hot (20)

Sling Models Overview
Sling Models OverviewSling Models Overview
Sling Models Overview
 
Sightly - Part 2
Sightly - Part 2Sightly - Part 2
Sightly - Part 2
 
Sling models by Justin Edelson
Sling models by Justin Edelson Sling models by Justin Edelson
Sling models by Justin Edelson
 
Experience and Content Fragment
Experience and Content FragmentExperience and Content Fragment
Experience and Content Fragment
 
Introduction to SASS
Introduction to SASSIntroduction to SASS
Introduction to SASS
 
HTL(Sightly) - All you need to know
HTL(Sightly) - All you need to knowHTL(Sightly) - All you need to know
HTL(Sightly) - All you need to know
 
AEM Best Practices for Component Development
AEM Best Practices for Component DevelopmentAEM Best Practices for Component Development
AEM Best Practices for Component Development
 
The six key steps to AEM architecture
The six key steps to AEM architectureThe six key steps to AEM architecture
The six key steps to AEM architecture
 
Aem sling resolution
Aem sling resolutionAem sling resolution
Aem sling resolution
 
CI/CD on AWS
CI/CD on AWSCI/CD on AWS
CI/CD on AWS
 
(DVO306) AWS CodeDeploy: Automating Your Software Deployments
(DVO306) AWS CodeDeploy: Automating Your Software Deployments(DVO306) AWS CodeDeploy: Automating Your Software Deployments
(DVO306) AWS CodeDeploy: Automating Your Software Deployments
 
AEM Sightly Template Language
AEM Sightly Template LanguageAEM Sightly Template Language
AEM Sightly Template Language
 
Adobe AEM core components
Adobe AEM core componentsAdobe AEM core components
Adobe AEM core components
 
SPA Editor - Adobe Experience Manager Sites
SPA Editor - Adobe Experience Manager SitesSPA Editor - Adobe Experience Manager Sites
SPA Editor - Adobe Experience Manager Sites
 
JCR - Java Content Repositories
JCR - Java Content RepositoriesJCR - Java Content Repositories
JCR - Java Content Repositories
 
AEM (CQ) Dispatcher Caching Webinar 2013
AEM (CQ) Dispatcher Caching Webinar 2013AEM (CQ) Dispatcher Caching Webinar 2013
AEM (CQ) Dispatcher Caching Webinar 2013
 
AEM (CQ) Dispatcher Security and CDN+Browser Caching
AEM (CQ) Dispatcher Security and CDN+Browser CachingAEM (CQ) Dispatcher Security and CDN+Browser Caching
AEM (CQ) Dispatcher Security and CDN+Browser Caching
 
Mastering the Sling Rewriter
Mastering the Sling RewriterMastering the Sling Rewriter
Mastering the Sling Rewriter
 
Angular 8
Angular 8 Angular 8
Angular 8
 
Introduction to sass
Introduction to sassIntroduction to sass
Introduction to sass
 

Viewers also liked

AEM 6 - Client Context Personalization
AEM 6 - Client Context Personalization AEM 6 - Client Context Personalization
AEM 6 - Client Context Personalization
Prabhdeep Singh
 
When dispatcher caching is not enough...
When dispatcher caching is not enough...When dispatcher caching is not enough...
When dispatcher caching is not enough...
Jakub Wadolowski
 
SQFI 26 August 2010
SQFI 26 August 2010SQFI 26 August 2010
SQFI 26 August 2010
tqainc606
 
Dandelion Statement of Qualifications 2
Dandelion Statement of Qualifications 2Dandelion Statement of Qualifications 2
Dandelion Statement of Qualifications 2
Mary O'Donnell Meldrum
 
When dispatcher caching is not enough... (extended version)
When dispatcher caching is not enough... (extended version)When dispatcher caching is not enough... (extended version)
When dispatcher caching is not enough... (extended version)
Jakub Wadolowski
 
Subsystems: For those occasions where bundles are just too small... - Graham ...
Subsystems: For those occasions where bundles are just too small... - Graham ...Subsystems: For those occasions where bundles are just too small... - Graham ...
Subsystems: For those occasions where bundles are just too small... - Graham ...
mfrancis
 

Viewers also liked (19)

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

Similar to AEM - Client Libraries

Scaling Rails With Torquebox Presented at JUDCon:2011 Boston
Scaling Rails With Torquebox Presented at JUDCon:2011 BostonScaling Rails With Torquebox Presented at JUDCon:2011 Boston
Scaling Rails With Torquebox Presented at JUDCon:2011 Boston
benbrowning
 
Instagram filters (8 24)
Instagram filters (8 24)Instagram filters (8 24)
Instagram filters (8 24)
Ivy Rueb
 
DRILETT_AWS_VPC_Presentation_2MB
DRILETT_AWS_VPC_Presentation_2MBDRILETT_AWS_VPC_Presentation_2MB
DRILETT_AWS_VPC_Presentation_2MB
David Rilett
 

Similar to AEM - Client Libraries (20)

Best Practices for Building WordPress Applications
Best Practices for Building WordPress ApplicationsBest Practices for Building WordPress Applications
Best Practices for Building WordPress Applications
 
Best Practices for WordPress
Best Practices for WordPressBest Practices for WordPress
Best Practices for WordPress
 
Servlet programming
Servlet programmingServlet programming
Servlet programming
 
Introduction to Jquery
Introduction to JqueryIntroduction to Jquery
Introduction to Jquery
 
Making Of PHP Based Web Application
Making Of PHP Based Web ApplicationMaking Of PHP Based Web Application
Making Of PHP Based Web Application
 
Servlet programming
Servlet programmingServlet programming
Servlet programming
 
Intro JavaScript
Intro JavaScriptIntro JavaScript
Intro JavaScript
 
Basics of Backbone.js
Basics of Backbone.jsBasics of Backbone.js
Basics of Backbone.js
 
Enterprise WordPress - Performance, Scalability and Redundancy
Enterprise WordPress - Performance, Scalability and RedundancyEnterprise WordPress - Performance, Scalability and Redundancy
Enterprise WordPress - Performance, Scalability and Redundancy
 
Scaling Rails With Torquebox Presented at JUDCon:2011 Boston
Scaling Rails With Torquebox Presented at JUDCon:2011 BostonScaling Rails With Torquebox Presented at JUDCon:2011 Boston
Scaling Rails With Torquebox Presented at JUDCon:2011 Boston
 
Incremental DOM and Recent Trend of Frontend Development
Incremental DOM and Recent Trend of Frontend DevelopmentIncremental DOM and Recent Trend of Frontend Development
Incremental DOM and Recent Trend of Frontend Development
 
Asp.net With mvc handson
Asp.net With mvc handsonAsp.net With mvc handson
Asp.net With mvc handson
 
Instagram filters (8 24)
Instagram filters (8 24)Instagram filters (8 24)
Instagram filters (8 24)
 
WEB TECHNOLOGY Unit-3.pptx
WEB TECHNOLOGY Unit-3.pptxWEB TECHNOLOGY Unit-3.pptx
WEB TECHNOLOGY Unit-3.pptx
 
DRILETT_AWS_VPC_Presentation_2MB
DRILETT_AWS_VPC_Presentation_2MBDRILETT_AWS_VPC_Presentation_2MB
DRILETT_AWS_VPC_Presentation_2MB
 
Instagram filters (8 24)
Instagram filters (8 24)Instagram filters (8 24)
Instagram filters (8 24)
 
Webpack Introduction
Webpack IntroductionWebpack Introduction
Webpack Introduction
 
JS BASICS JAVA SCRIPT SCRIPTING
JS BASICS JAVA SCRIPT SCRIPTINGJS BASICS JAVA SCRIPT SCRIPTING
JS BASICS JAVA SCRIPT SCRIPTING
 
JavaScript Service Worker Design Patterns for Better User Experience
JavaScript Service Worker Design Patterns for Better User ExperienceJavaScript Service Worker Design Patterns for Better User Experience
JavaScript Service Worker Design Patterns for Better User Experience
 
Apache Drill (ver. 0.2)
Apache Drill (ver. 0.2)Apache Drill (ver. 0.2)
Apache Drill (ver. 0.2)
 

Recently uploaded

+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
VishalKumarJha10
 

Recently uploaded (20)

Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...
 

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.