Skip to main content

AEM Clientlib Versioning

AEM Clientlib Versioning


Clientlib versioning allows CSS and javascript which is served by aem clientlibs to be cached for a very long time which in turn reduces the page load time of the website and improves performance. It has various benefits like -

  • Longer TTL for cached client libraries.
  • Improved web and site performance by reducing page load time.
  • No more inconsistent data from the normal client library.

How it works -

  • It uses Sling Rewriter to rewrite the client libraries and append a unique MD5 value at the end of the client library URL.
  • This url get cache later.
  • This MD5 value is unique for the code of ClientLibs. 
  • If there is a modification in code or ClientLibs, a new MD5 value will be generated and appended to the client library URL this allows it to recache.

Steps to create Clientlib version:

  1. Login to http://localhost:4502/crx/de/index.jsp
  2. Go to /apps/<your-project>/config 
  3. Create a nt:unstructured folder by name it as a rewriter
  4. Go to /libs/cq/config/rewriter/default
  5. Copy the default node and paste it under your project config folder
It will look like this -

versioned-clientlibs

Configure Apache to send the right headers so that it can be cached. Example

Apache server configuration

Versioned ClientLibs URL will look like this:

https://localhost:4502/etc.clientlibs/we-practice/clientlibs/sales.min. 8d1738c51ad22dacbbbec37f85734bac.js

Note -

For loading versioned ClientLibs for the first time you need to restart AEM instance.

Validation -

· Navigate to http://localhost:4502/system/console/status-slingrewriter

· Search for resource path where versioned clientlibs is created /apps/<project-name>/config/rewriter/versioned-clientlib. If a resource path is found under the sling rewriter. That means the configuration is working fine.

Comments

Popular posts from this blog

AEM 6.3 - How to extend Granite UI

Here in this article, I am going to explain how to extent Granite UI that is basically used to create AEM 6.x consoles. There can be various use cases where in you may need that. In our case, author wants to take all the page creation requests through AEM instead of email communication. Authors are basically looking for a form in AEM authoring console so that requestor can login and submit page creation/Asset upload request. Overall requirement is - Need a link in Navigation so that author can click on it and go to a Intake form. Author must be able to fill and save the intake requests. Author must be able to see the history of submitted intake requests Able to see the details of submitted intake requests. Solution - 1. Create a following structure - /apps/cq/core/content/nav/form and add the details given in below screenshot - You basically need to add - href, title and icon. Href is the path of page where user will land on clicking it.  Af...

CQ Page Properties from Javascript

To get CQ page properties inside javascript you can use core CQ JS API. It can be convenient if you need to get this information inside your custom JS widgets.              var pageData = CQ.HTTP.get(CQ.HTTP.externalize(CQ.utils.WCM.getPagePath() + "/jcr:content.json")); After that you can retrieve any property you need (assuming it's present in JCR):              var resourceType = pageData ? CQ.Util.formatData(CQ.HTTP.eval(pageData))['sling:resourceType'] : null; Please do not overuse it because it invokes additional ajax call to server. It's OK to use it in edit mode on author instance. Copied from -  http://adobecms.blogspot.com/2014/04/cq-page-properties-in-javascript.html

AEM 6.3 - Check if page is published or not

If you want to know if the page is published or not you can use the below utility method to know if the page is published or not. Steps - Take Resource Object. Adapt it to Page Adapt page to ReplicationStatus, you will get the status Here is the code - public static Boolean isPublished(Resource resource) { Boolean activated; ReplicationStatus status = null; activated = false; if (resource != null) { try { Page page = resource.adaptTo( Page.class ); status = page.adaptTo( ReplicationStatus.class ); } catch (Exception e) { LOG.debug(e.getMessage (), e); } if (status != null) { activated = status.isActivated(); } } return activated; }