Statement : How to merge multiple JS/CSS files into one
Solution :
How to embed multiple categories.
Reference Article : http://blogs.adobe.com/experiencedelivers/experience-management/clientlibs-explained-example/
Solution :
- In this example used proxy clientlibs approach, this is available and recommended since AEM6.2
- The AEM Client Library (or ClientLib) functionality will manage all your JavaScript and CSS resources in your application. It takes cares of dependency management, merging files and minifying content (removing unnecessary white spaces).
The following application scenarios will be explained:
- multiple components with their own JavaScript and CSS files
- CSS resources have to go in the , JavaScript resources at the end of the page
- Resources need to be minified
- changing the minification engine
Let’s get started!
Step 1: Creating components and ClientLib nodes
First we make a few components, in this example 3 components are used, we do this all via CRXDE-lite (http://localhost:4502/crx/de).
Next we are going to add a “clientlib” node of type “cq:ClientLibraryFolder”, inside this node the JavaScript and CSS resources are stored.
Add a property to every “clientlib” node called “categories” of type String[] with the single value of “myproject.components” (to get a String[] type click the “Multi” button).
Now add a Boolean property “allowProxy”, and set this to true. This will make the clientlibs available via the url /etc.clientlibs/, so it means they are not having the /apps reference.
Your components-folder will look now like this:
Step 2: Adding JavaScript and CSS resources
Now we are going to add some simple JavaScript and CSS resources in the “clientlib” nodes.
Create following files inside of your “clientlib” folder of “MyFirstComponent”:
first.css
.firstContainer {
margin-top:10px;
}
first.js
/*
* This is the comment of the function
*/
function getNameFirst() {
// return the name
return "some value";
}
js.txt
# mentions all the JavaScript resources of the ClientLib
first.js
css.txt
# mentions all the CSS resources of the ClientLib
first.css
And repeat the same thing for the other components to achieve something that looks like this:
The configuration of the components are now finished.
Step 3: Using ClientLibs in your component
Now the setup of the ClientLib is finished we can invoke the ClientLibs in your page components. When you are using a JSP you can use cq:includeClientlib . In case you are using the HTML Template Language (HTL), you can use the data-sly-call to invoke the ClientLib. In this article HTL will be used for the examples.
We start with putting the following into the element of our page:
The value of the “categories” properties of the “clientlib” nodes are “myproject.components”, which is what we need to provide above.
This results in the following HTML-output:
This has a few downsides:
- 6 server calls have to be made to fetch the resources.
- Application structure is exposed.
Step 4: Merging files
To merge the several clientlib files into one, we define a clientlibs that is embedding the other categories. Example here is taken from /apps/weretail/clientlibs/clientlib-base.
Step 5: Dependencies
Another property you can add to the “clientlib” node is “dependencies”, this way you can define dependencies between ClientLibs.
Let’s add a dependency on “cq.jquery”:
When you now reload the page the dependency is written:
Step 6: Minify and Gzip
To deliver a better performance you can enable “Minify” and “Gzip” for the “Adobe Granite HTML Library Manager” (previously also called “Day CQ HTML Library Manager”), in the Felix Configuration console (http://server/system/console/configMgr). These settings are recommended for production installations.
By default the YUI compressor is used when minifying files, you can better use the GCC (Google Clojure Compiler) for this.
This is described here: https://helpx.adobe.com/experience-manager/kb/how-to-change-the-minification-engine-for-client-libraries-in-AEM.html
Common error with proxy clientlibs
When you use proxy clientlibs, then you may run into this error:
“Unable to proxy yourfont.ttf. No supported type for .ttf”, this can happen for types other than JS/CSS.
Reason for this is that resources other than JS/CSS need to be put into a folder called resources.
FAQ
Q: I don’t want to have all my JavaScript references in the
A: Move the data-sly-call to the right location in your template, you can use ClientLib multiple times
A: Move the data-sly-call to the right location in your template, you can use ClientLib multiple times
Q: Where are the generated files stored in AEM?
A: They are stored in /var/clientlibs
A: They are stored in /var/clientlibs
Q: When developing I want to have single file references in my HTML
A: Enable the debug-option in the HTML Library Manager
A: Enable the debug-option in the HTML Library Manager
Q: Is there a console so I can see the dependencies?
A: Yes, look at this page http://server/libs/cq/ui/content/dumplibs.html
A: Yes, look at this page http://server/libs/cq/ui/content/dumplibs.html
Q: Are there debugging options available?
A: Yes, ?debugClientLibs=true writes out single files
A: Yes, ?debugClientLibs=true writes out single files
Q: Can I rebuild the ClientLibs?
A: Yes, via this url: /libs/granite/ui/content/dumplibs.rebuild.html
A: Yes, via this url: /libs/granite/ui/content/dumplibs.rebuild.html
Q: How can I use cache-busting and ClientLibs?
A: You can enable the hashing of the url via ‘versioned ClientLibs’.
A: You can enable the hashing of the url via ‘versioned ClientLibs’.
Q: Do you have an example of this?
A: Yes, the “core” components can be used as a reference: https://git.corp.adobe.com/CQ/aem-core-wcm-components
A: Yes, the “core” components can be used as a reference: https://git.corp.adobe.com/CQ/aem-core-wcm-components
Q: What is the best practice with regards to performance and caching
A: Via mod_expires / mod_deflate and the use of cache-busting you can cache the css/js files on the browser to increase overall performance of your pages. All of this will happen in combination with the dispatcher.
A: Via mod_expires / mod_deflate and the use of cache-busting you can cache the css/js files on the browser to increase overall performance of your pages. All of this will happen in combination with the dispatcher.
How to embed multiple categories.
In AEM, a category include will merge and compress all the files into a single js (or css) include. This is done per category include.
If you want to merge multiple categories, you should consider using the embed option in categories dependencies. How this works is:
- Create a new category (for e.g. cq-embed)
- Define embed dependencies ('cq.foundation-main','cq.shared') for the new category you have created.
- Reference your new category.
Reference Article : http://blogs.adobe.com/experiencedelivers/experience-management/clientlibs-explained-example/
Hello! I could have sworn I’ve visited your
ReplyDeleteblog before but after going through some of
the articles I realized it’s new to me. Nonetheless, I’m
certainly delighted I found it and I’ll be bookmarking it
and checking back regularly!
bookmarked!!, I really like your site!
ReplyDeleteYou've made some really good points there. I looked on the net to find out more about the issue and found most individuals will go along with your views on this web site.
ReplyDeleteMay I simply say what a comfort to discover
ReplyDeletesomebody who genuinely knows what they're talking about on the web.
You certainly know how to bring an issue to light and make it
important. More people really need to read this and understand this side of the story.
I was surprised you are not more popular because you surely have the
gift.
Saved as a favorite, I like your blog!
ReplyDeleteGood post. I learn something totally new and challenging
ReplyDeleteon sites I stumbleupon on a daily basis. It's always exciting to read
content from other writers and practice a little something from their websites.
Greetings, There's no doubt that your site could be having browser compatibility problems.
ReplyDeleteWhen I take a look at your site in Safari, it looks fine but when opening in IE, it has some overlapping issues.
I merely wanted to provide you with a quick heads up! Apart
from that, wonderful website!
Aw, this was an extremely nice post. Spending some time and actual effort to generate
ReplyDeletea good article… but what can I say… I procrastinate a whole lot and
don't manage to get nearly anything done.
Pretty! This was a really wonderful article.
ReplyDeleteThanks for supplying this information.
Spot on with this write-up, I actually believe this amazing site needs a lot more attention. I’ll probably be back again to read more, thanks for the advice!
ReplyDeleteAw, this was an extremely nice post. Taking the time and actual
ReplyDeleteeffort to make a great article… but what can I say… I put
things off a lot and don't manage to get anything done.
It’s hard to come by educated people for this subject, but you sound like
ReplyDeleteyou know what you’re talking about! Thanks
Aw, this was an exceptionally good post. Spending some time and actual
ReplyDeleteeffort to create a very good article… but what can I say… I hesitate a whole lot and never manage to get anything
done.
You need to take part in a contest for one
ReplyDeleteof the best blogs on the web. I'm going to recommend this blog!
I was able to find good advice from your blog articles.
ReplyDeleteHi, I do believe this is a great blog. I stumbledupon it ;) I'm going to revisit yet again since I book marked it.
ReplyDeleteMoney and freedom is the greatest way to change,
may you be rich and continue to help others.
May I simply say what a comfort to discover someone who
ReplyDeletereally knows what they're talking about online. You
actually understand how to bring an issue to light and make it important.
More and more people really need to read this and understand this side of the story.
It's surprising you are not more popular since you most certainly have the
gift.
There's certainly a great deal to know about this subject.
ReplyDeleteI really like all the points you have made.
I used to be able to find good info from your articles.
ReplyDeleteHello! I could have sworn I’ve visited this site before but
ReplyDeleteafter browsing through a few of the articles I realized it’s new to me.
Anyhow, I’m definitely pleased I found it and I’ll be book-marking it and checking
back frequently!
I’m impressed, I have to admit. Rarely do I come
ReplyDeleteacross a blog that’s both equally educative and engaging, and let me tell
you, you've hit the nail on the head. The issue is an issue that not enough people are speaking
intelligently about. Now i'm very happy that I found this in my
hunt for something concerning this.
You are so cool! I do not believe I've truly read something like this before.
ReplyDeleteSo good to find somebody with original thoughts on this subject matter.
Really.. many thanks for starting this up.
This website is one thing that's needed on the internet,
someone with some originality!
This is a topic that is near to my heart...
ReplyDeleteThank you! Where are your contact details though?
Howdy! I could have sworn I’ve visited this website before but after going through a few of the posts I realized it’s new to
ReplyDeleteme. Nonetheless, I’m definitely happy I stumbled upon it and I’ll be book-marking it and checking back often!
May I simply say what a relief to discover somebody that really knows what they're discussing on the web.
ReplyDeleteYou certainly understand how to bring an issue to light and make it important.
A lot more people have to read this and understand this side of your story.
It's surprising you are not more popular since you definitely have
the gift.
Excellent article. I will be experiencing many of these issues as well..
ReplyDeleteThis is a very good tip especially to those fresh to the blogosphere.
ReplyDeleteSimple but very precise info… Many thanks for sharing this one.
A must read post!
Way cool! Some very valid points! I appreciate you penning this write-up and the rest of the website is also really good.
ReplyDeleteI could not resist commenting. Perfectly written!
ReplyDeleteAfter going over a handful of the blog posts on your website,
ReplyDeleteI honestly appreciate your technique of blogging.
I saved it to my bookmark webpage list and will be checking
back soon. Please visit my web site too and let me know your opinion.
Spot on with this write-up, I actually think this website
ReplyDeleteneeds far more attention. I’ll probably be returning to read through more,
thanks for the information!
Saved as a favorite, I like your website!
ReplyDeleteYou're so interesting! I don't believe I have read through
ReplyDeletesomething like this before. So wonderful to find somebody with a few original
thoughts on this subject matter. Really.. thank you for starting this up.
This website is one thing that is required on the internet, someone with a bit of originality!
I truly love your blog.. Excellent colors & theme. Did you build this
ReplyDeleteamazing site yourself? Please reply back as I’m looking to create my own personal site and would
love to find out where you got this from or what the theme is called.
Thanks!
I was excited to discover this site. I need to to thank you for ones
ReplyDeletetime for this fantastic read!! I definitely appreciated every little bit of it and
i also have you book marked to look at new stuff in your website.
Aw, this was a really nice post. Spending some time and actual effort to produce a good article… but
ReplyDeletewhat can I say… I hesitate a whole lot and never manage
to get nearly anything done.
Excellent web site you have got here.. It’s hard
ReplyDeleteto find high-quality writing like yours nowadays. I really appreciate people like
you! Take care!!
Excellent site you've got here.. It’s difficult to find quality writing like yours these days.
ReplyDeleteI really appreciate individuals like you! Take care!!
I’m amazed, I must say. Seldom do I come across a blog that’s
ReplyDeleteboth equally educative and amusing, and let me tell you, you have hit the nail on the head.
The issue is something which not enough people are speaking intelligently about.
Now i'm very happy I stumbled across this in my search for something
concerning this.
Spot on with this write-up, I honestly believe this website needs far more attention. I’ll probably be back again to see more,
ReplyDeletethanks for the advice!
Hi, I do think this is a great blog. I stumbledupon it ;) I will come back yet
ReplyDeleteagain since i have bookmarked it. Money and
freedom is the greatest way to change, may you be rich and continue to guide other people.
This site was... how do I say it? Relevant!! Finally I've found something
ReplyDeletethat helped me. Many thanks!
I’m impressed, I must say. Rarely do I come across a blog that’s both equally educative and interesting, and without a doubt,
ReplyDeleteyou have hit the nail on the head. The issue is something too few people are speaking intelligently about.
Now i'm very happy I came across this during my hunt
for something relating to this.
I have to thank you for the efforts you have put in penning
ReplyDeletethis site. I'm hoping to see the same high-grade
content by you later on as well. In fact, your creative writing abilities has motivated me to get my
own blog now ;)
Much obliged for your data, it was truly exceptionally helpfull..
ReplyDeletecss beautify
I was able to find good information from your
ReplyDeleteblog posts.
I used to be able to find good information from your blog articles.
ReplyDeleteThis is a topic which is close to my heart... Cheers!
ReplyDeleteWhere are your contact details though?
Greetings! Very useful advice in this particular article!
ReplyDeleteIt's the little changes which will make the
most significant changes. Thanks for sharing!
Next time I read a blog, Hopefully it does not fail me just as much as this one.
ReplyDeleteI mean, I know it was my choice to read through, nonetheless I actually
thought you would have something helpful to say. All I hear is a bunch of moaning about something you could
fix if you weren't too busy searching for attention.
Hello there! I could have sworn I’ve been to this website before but after looking at many of the posts I realized it’s new to me.
ReplyDeleteAnyways, I’m certainly delighted I came across it and I’ll be book-marking it
and checking back often!
Having read this I thought it was extremely informative.
ReplyDeleteI appreciate you spending some time and energy to put this
information together. I once again find myself spending a significant
amount of time both reading and posting comments. But so what, it was still worthwhile!
Good post. I learn something totally new and challenging on sites I stumbleupon on a daily basis.
ReplyDeleteIt's always interesting to read through content from other writers and practice
something from other web sites.
I blog often and I genuinely appreciate your content.
ReplyDeleteThis article has truly peaked my interest.
I'm going to bookmark your blog and keep checking for new details about once per week.
I opted in for your Feed too.
An interesting discussion is worth comment. I do believe that
ReplyDeleteyou should publish more about this subject, it
might not be a taboo matter but usually people do not discuss such subjects.
To the next! All the best!!
A fascinating discussion is worth comment.
ReplyDeleteI think that you ought to write more about this subject, it might
not be a taboo matter but generally people don't talk about these topics.
To the next! Best wishes!!
Hey there! I just wish to offer you a big thumbs up for the great
ReplyDeleteinfo you have got here on this post. I'll be coming back to your blog for
more soon.
Good web site you have here.. It’s difficult to find
ReplyDeletehigh-quality writing like yours nowadays. I really appreciate people
like you! Take care!!
An intriguing discussion is definitely worth comment.
ReplyDeleteI do think that you should write more about this topic,
it might not be a taboo matter but usually folks don't
talk about such topics. To the next! Cheers!!
I want to to thank you for this fantastic read!! I definitely loved every little bit of it.
ReplyDeleteI have got you book-marked to check out new things
you post…
Howdy! I could have sworn I’ve visited this web site before but after
ReplyDeletegoing through a few of the articles I realized it’s new to me.
Regardless, I’m certainly happy I discovered it and I’ll be book-marking it and
checking back often!
Good post. I certainly appreciate this website.
ReplyDeleteKeep it up!
There is certainly a lot to find out about this topic.
ReplyDeleteI like all the points you have made.
Spot on with this write-up, I seriously think this site needs a lot more
ReplyDeleteattention. I’ll probably be back again to read more, thanks for the advice!
Very good article. I will be experiencing many of these issues as well..
ReplyDeleteYou need to take part in a contest for one of the greatest sites on the internet.
ReplyDeleteI most certainly will highly recommend this blog!
Oh my goodness! Impressive article dude! Thank you, However
ReplyDeleteI am encountering problems with your RSS. I don’t
know the reason why I am unable to subscribe to it.
Is there anyone else getting similar RSS issues?
Anyone that knows the solution can you kindly respond?
Thanks!!
Pretty! This was an extremely wonderful post.
ReplyDeleteMany thanks for providing this information.
Hi there! This post couldn’t be written much better!
ReplyDeleteReading through this post reminds me of my previous roommate!
He always kept preaching about this. I will send this post to
him. Fairly certain he'll have a very good read.
Thanks for sharing!
Aw, this was an incredibly nice post. Finding
ReplyDeletethe time and actual effort to create a good article… but what
can I say… I hesitate a lot and don't manage to
get nearly anything done.
I truly love your website.. Excellent colors & theme. Did you
ReplyDeletebuild this amazing site yourself? Please reply back
as I’m trying to create my very own blog and would love
to learn where you got this from or just what the theme is named.
Cheers!
Greetings! Very useful advice in this particular article!
ReplyDeleteIt is the little changes that produce the greatest changes.
Thanks for sharing!
Pretty! This has been an extremely wonderful article. Thanks
ReplyDeletefor providing this info.
I need to to thank you for this great read!!
ReplyDeleteI definitely loved every little bit of it. I've got you book marked to look at new stuff you post…
Hi there, I believe your blog might be having internet browser compatibility issues.
ReplyDeleteWhenever I look at your website in Safari, it looks fine however,
when opening in IE, it's got some overlapping issues.
I simply wanted to give you a quick heads up! Aside from that, wonderful website!
I wanted to thank you for this good read!! I absolutely
ReplyDeleteloved every little bit of it. I have you book marked to
look at new things you post…
Spot on with this write-up, I actually believe that this site needs far more attention. I’ll probably be back again to read through more, thanks for the info!
ReplyDeleteWhen I initially commented I seem to have clicked on the -Notify
ReplyDeleteme when new comments are added- checkbox and from now on each time a comment is added I recieve 4 emails with the same
comment. There has to be a way you can remove me from that
service? Thanks a lot!
That is a good tip particularly to those fresh to the
ReplyDeleteblogosphere. Simple but very precise information… Many thanks for sharing this
one. A must read post!
Can I just say what a comfort to discover somebody that actually knows what they're talking about on the web.
ReplyDeleteYou certainly understand how to bring an issue to light and make it important.
More and more people should read this and understand this side of your story.
I was surprised you are not more popular since you definitely possess the gift.
Way cool! Some very valid points! I appreciate you penning this write-up and the rest
ReplyDeleteof the site is also very good.
It’s nearly impossible to find well-informed people about this subject,
ReplyDeletehowever, you seem like you know what you’re talking about!
Thanks
You've made some good points there. I checked on the web to
ReplyDeletelearn more about the issue and found most people will go along with
your views on this site.
I really like reading through an article that will make
ReplyDeletemen and women think. Also, many thanks for allowing me to
comment!
I quite like reading through an article that will make people think.
ReplyDeleteAlso, thanks for allowing me to comment!
You need to be a part of a contest for one of the most useful
ReplyDeleteblogs on the internet. I'm going to highly recommend this site!
Everything is very open with a really clear explanation of the issues.
ReplyDeleteIt was really informative. Your website is very helpful.
Thanks for sharing!
I’m amazed, I have to admit. Rarely do I come across a
ReplyDeleteblog that’s both educative and engaging, and let me tell you,
you have hit the nail on the head. The issue is something not enough men and
women are speaking intelligently about. I am very happy that I
found this in my hunt for something relating to this.
Great web site you've got here.. It’s difficult to find excellent writing like yours
ReplyDeletenowadays. I truly appreciate individuals like you!
Take care!!
After looking at a few of the articles on your web site,
ReplyDeleteI seriously appreciate your way of writing a blog.
I book-marked it to my bookmark site list and will be checking back soon. Please
check out my website too and tell me how you feel.
Oh my goodness! Awesome article dude! Thank you so much, However
ReplyDeleteI am encountering problems with your RSS. I don’t know why I can't subscribe to
it. Is there anybody else having the same RSS problems? Anyone who knows the answer can you kindly respond?
Thanx!!
Hi, I do believe your site may be having web browser compatibility problems.
ReplyDeleteWhenever I take a look at your website in Safari, it looks fine
but when opening in I.E., it has some overlapping issues.
I simply wanted to give you a quick heads up! Other than that,
great website!
That is a very good tip especially to those new to the blogosphere.
ReplyDeleteBrief but very accurate info… Thank you for sharing
this one. A must read post!
You need to be a part of a contest for one of
ReplyDeletethe highest quality websites on the web. I am going to highly
recommend this blog!
I could not refrain from commenting. Well written!
ReplyDeleteMay I simply say what a relief to uncover an individual who
ReplyDeletetruly knows what they are talking about
online. You definitely realize how to bring a problem to
light and make it important. More and more people need to read this and
understand this side of your story. I was surprised
that you aren't more popular because you certainly have the gift.
Everyone loves it when people come together and share thoughts.
ReplyDeleteGreat site, stick with it!
You ought to take part in a contest for one of the finest sites on the
ReplyDeletenet. I'm going to highly recommend this web site!
You need to be a part of a contest for one of
ReplyDeletethe most useful blogs on the web. I am going to highly recommend this
blog!
I could not resist commenting. Perfectly written!
ReplyDeleteYou made some really good points there. I
ReplyDeletelooked on the net for more info about the issue and found most individuals will go along with your views on this website.
After looking at a number of the articles on your website, I honestly appreciate your way of writing a
ReplyDeleteblog. I book-marked it to my bookmark webpage list and will be checking back
soon. Take a look at my web site too and tell
me what you think.
A motivating discussion is worth comment. I do believe that you need to write more on this subject
ReplyDeletematter, it might not be a taboo matter but generally folks don't speak about these issues.
To the next! Best wishes!!
Everything is very open with a precise clarification of the
ReplyDeleteissues. It was definitely informative. Your website is very helpful.
Many thanks for sharing!
Very good info. Lucky me I ran across your site by accident (stumbleupon).
ReplyDeleteI've book-marked it for later!
Howdy, I think your site could possibly be having internet browser compatibility problems.
ReplyDeleteWhenever I look at your site in Safari, it looks fine however
when opening in Internet Explorer, it's got some overlapping
issues. I merely wanted to provide you with a quick heads up!
Besides that, wonderful site!
Thanks to all...for a motivating note
ReplyDeleteMy brother suggested I might like this blog. He was totally right.
ReplyDeleteThis post actually made my day. You cann't imagine just how much time I had spent
for this information! Thanks!
How htmllibraryManager merging code when we add a property embed to the node??
ReplyDelete