Hello Everyone,
This is one of my most awaited blog,So I am glad to share this with you all.
ClientLibs is having an OSGi Configuration in the felix console named:
Adobe Granite HTML Library Manager
Here ,We are going to explain each and every option in this configuration in detail.
1.Minify:
- If we checked minification,it will compress all the js/css files by removing all the spaces and extra lines of files.
- To enable this configuration in Production server is mandatory,because it will decrease the response time of the page.But not use in Dev Server,because css/js files will become difficult to debug.
Fig- Network Calls(CSS/JS)Before Minification |
Fig- Network Calls(CSS/JS)AfterMinification |
- It minifies all the css /js files by renaming it like fileName.min.js.
Fig-removes extra space after minification |
2.Debug:
- This configuration is checked in Dev Server,because this configuration doesn’t concatenate the clientlibs and serve js and css files individually.
- Helps in debugging.
- This will prevent the CQ clientlibs files from being combined into one file, and makes troubleshooting JavaScript and css issues significantly easier.
- Enable this configuration is equivalent to adding ?debugClientLibs=true.
3.Gzip:
- This is also a mandatory configuration in Production server because it also helps in loading the page quickly.
Without Gzip:
Fig-Response Without Gzip |
In the above diagram:
- The browser requests a file index.html from the server.
- The server provides the html as a response.
- The response provides a 100KB file and Browser displays a page after downloading so much data.
Let’s find out a better solution.
➤The Server is sending a large amount of data.If we have a large file and we need to send it to someone,what we use to do?
➤We just Zip it and send it to the receiver.So if we could send a zip file to the browser,it will save a lot of download time and bandwidth.
How GZip works?
How GZip works?
-
Fig-Reduced Response after GZip The browser sends a header telling the server it accepts compressed content (gzip and deflate are two compression schemes): Accept-Encoding: gzip, deflate - The server sends a response if the content is actually compressed: Content-Encoding: gzip
Our job is to configure the server so it returns zipped content if the browser can handle it, saving bandwidth for everyone and giving us a happy user.
Fig-Network calls without Gzip |
Fig-Network calls withGzip |
An ideal Request and Response for Gzip is:
Note: While enable Gzip in the OSGi Configuration,activate the bundle (Adobe Granite Ui Clientlibs Bundle) and clear the cache.Sometimes after enabling it, It serves the request from the cache.So to clear the cache is important.Also don’t forget to check the Accept-Encoding in the request headers and Content-Encoding in the response headers.
4.Timing: This enables the JS Load timing statistics.
So add a query Parameter ?debugClientlibs=true in the page url and hit Ctrl+Shift+U.
Fig:Timing |
5.FireBug Lite Path:Path in the workspace where the firebug-lite.js file is located. The script should make sure it does not activate if the real firebug is present. Default: "/libs/widgets/cq-widgets.js/files/endorsed/ firebug/firebug-lite.js "
6.Debug Console: To activate this configuration is equivalent to adding "debugConsole=true" in the page Path.If we activate this configuration, FireBug Lite gets activated in the browser.
Browsers has online plugins to install FireBug Lite in the browser that help to debug the css/js files.So the workspace firebug-lite.js will executed if it doesn’t find the file in the browser.
7.Force CQURLInfo:
Enabling this configuration provides "CQURLInfo" jquery object in the AEM page console.If disabled,this object will come as "undefined" in browser console.
Fig-Implicit Object CQURLInfo in the AEM Page |
8.Max Age:This directive specifies the maximum time in seconds that the fetched response is allowed to be reused from the browser cache within that time of the request. For example, "max-age=50" indicates that the response can be cached and reused for the next 50 seconds.
Fig-Max Age in the Response Header |
You can check the cached files in chrome from here “chrome://cache/”.
9.Allowed Library path:This configuration indicates that from which locations clientlibs are allowed to be loaded.The default values are “/apps,/libs,/etc”.
Fig-Allowed Library Path |
The Demonstration video on CQURLInfo, Max-Age and Allowed Library Path:
10.JS/CSS Processor Default Config:
10.JS/CSS Processor Default Config:
The default value of this configuration is "min:yui".
The full form of yui is Yahoo! User Interface Library.
- According to Yahoo!'s Exceptional Performance Team, 40% to 60% of Yahoo!'s users have an empty cache experience and about 20% of all pageviews are done with an empty cache.
- This fact outlines the importance of keeping web pages as lightweight as possible. Improving the engineering design of a page or a web application usually yields the biggest savings and that should always be a primary strategy.
- With the right design in place, there are many secondary strategies for improving performance such as minification of the code,
So YUI is a tool that helps in compression of js/css files.
Fig-JS/CSS Processor |
You can use any other compressor as well, As i tried with min:jquery. You can find alternatives of yui from here https://w3techs.com/technologies/compselect/js-yui.
11.Max Data URI Size: The minification of css-files can auto-inline small resources (e.g. icons). The config-parameter “htmllibmanager.maxDataUriSize” steers maximum size for resources to be auto-inlined.
The Demonstration video on Max Data URI Size:
If you have any query or suggestion then kindly comment or mail us at sgaem.blog02@gmail.com
Let’s understand this with an example:
I have a css file like this:
I have a css file like this:
#tiny-icon { height: 32px; width: 32px; background-image: url("tiny-icon.gif"); }
|
If sample-icon has a size of 360 bytes. With maxDataUriSize <= 360, the minified css file will look:
#tiny-icon{height:32px;width:32px;background-image:url("test-alex/tiny-icon.gif")}
|
With maxDataURI Size > 360, the icon will be auto-inlined as data-url:
#tiny-icon{height:32px;width:32px;background-image:url("data:image/gif;base64,R0lGODlhIAAgAIQQAEeczSqmzligoGmarl6khnCdy3CpaBj
|
The format of data URI is:
data:[<mime type>][;charset=<charset>][;base64],<encoded data>
|
Note: Sometimes the configurations may not work because some of the configurations gets its value only when bundle is activated.So just restart the bundle shown below and everything will work fine.
Fig-Adobe Granite UI Clientlibs Bundle |
I am still exploring rest of the options related to this configuration. We will share an another blog on the same.
If you have any query or suggestion then kindly comment or mail us at sgaem.blog02@gmail.com
Hope it will help you guys !!
Thanks and Happy Learning .
When css or js issues appear it is useful to have a mapping option (where did the offending line originate). Are you aware of such an option is Granite HTML config?
ReplyDeleteHi David,I think there is no need of any configuration.Where you see the error,You can directly go to the js/css and open it in new tab.It will show you in the url from where the file is getting loaded.
DeleteNice blog. Could you add more details about "CQURLInfo".. Why and when it is needed?
ReplyDeleteThanks Vivek.Great Input. I will study this and will add this part in the blog asap.
DeleteHi vivek, As per my understanding it is something like I used to do in servlets.I can fetch request Resource,Selectors and suffixes in the servlet same as if we need all such things in JS to write our logic based on a selector, an extension or may be runMode ,It can help me.
DeleteGo through this sample example:https://optimum.com/etc/clientlibs/foundation/shared.js;70727
let me know Is this answers your query!
Thanks.
Can you quote an example here?
DeleteMinifying Angular JS code using YUI compressor may throw error. We are facing that issue. Eventhoug we included our clienlib path in the excluding list issue persist. We tried to use gcc compressor but not luck.
ReplyDeleteHi Adarsh, I have seen this issue very frequently, even excluded list option is not working that's why i have not included that option in my blog. One suggestion is you put minified version of your clientlibs in aem.That thing can help you.
DeleteFor Angular, you need to use grunt to minify it using uglify, concat and ng-annotate to safeguard it from minification screwing up the dependency injection. After that you can clientlibify it, you can use the one by Michael Leroy or Wcmio's. You can have these grunt tasks as a part of your maven build process.
DeleteYou will need to use the gcc minifier for the latest js files, YUI is at EOF and does not support these. The gcc jar files will have to be installed. Post that for the job files you need gcc to kick in add the below property :
DeletejsProcessor="[min:gcc]" (the property is String Multi valued)
Hope this answers the query.
Adarsh, if you have an example just file that fails with gcc pass those on and let me know the version of AEM that you are trying this on.
ReplyDeleteHi when I enable Debug .. my targeted offers stop loadibg
ReplyDeleteWe disable minify option and enabled debug option
DeleteHi Shivani,
ReplyDeleteI am getting "Failed to execute 'send' on 'XMLHttpRequest': Failed to load hostName/system/console/configMgr/com.adobe.granite.ui.clientlibs.impl.HtmlLibraryManagerImpl'." while enabling minify option. Can you help me with it?
Is there any option to minify the whole page HTML?
ReplyDelete