How to put defer attribute to AEM js libraries - to avoid render blocking issue. | Community
Skip to main content
ajeemaw
New Participant
Mar 15, 2021 12:13 PM UTC
Solved

How to put defer attribute to AEM js libraries - to avoid render blocking issue.

The above 2 resources are loading inside head element. but I could not find those in source code. I need to know where I can find this call & How can I put defer attribute to that?

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
davidjgonzalezzzzAccepted solution
Employee
Mar 15, 2021 3:39 PM UTC

Be careful about overlaying the OOTB headlibs.html and friends - there is a reason why Core Components Page has already seeded the implementation with "customheaderlibs.html" .. its because that's where you should put yours so you're not overlaying the provided one. If you overlay the provided HTML, what happens when Core Components/product changes something about them? Now you're stuck trying to manually reconcile changes down. Also, you lose the ability to use the clientlib include HTML template, which again, can evolve as new capabilities are added to the product.

 

 

8 replies

Nikhil-Kumar
New Participant
Mar 18, 2021 1:57 PM UTC

@ajeemaw - It seems like these are OOTB scripts. Can you verify what these scripts are doing ?

Thanks,
Nikhil Kumar

Translate
BrianKasingli
New Participant
Mar 15, 2021 6:27 PM UTC

You can implement a custom implementation like https://github.com/nateyolles/aem-clientlib-async

Translate
davidjgonzalezzzzAccepted solution
Employee
Mar 15, 2021 3:39 PM UTC

Be careful about overlaying the OOTB headlibs.html and friends - there is a reason why Core Components Page has already seeded the implementation with "customheaderlibs.html" .. its because that's where you should put yours so you're not overlaying the provided one. If you overlay the provided HTML, what happens when Core Components/product changes something about them? Now you're stuck trying to manually reconcile changes down. Also, you lose the ability to use the clientlib include HTML template, which again, can evolve as new capabilities are added to the product.

 

 

Translate
Asutosh_Jena_
New Participant
Mar 15, 2021 3:35 PM UTC

Hi @ajeemaw 

You cannot put a defer/async attribute to the clientlib files as this is currently not an OOTB feature supported by AEM. If you do not need these files to be loaded on the head section, you can overlay headlibs.html and add your custom code to load the required project specific clientlibs.

Please refer the file below from where the JS files are getting loaded.
https://github.com/adobe/aem-core-wcm-components/blob/development/content/src/content/jcr_root/apps/core/wcm/components/page/v2/page/headlibs.html

Hope this helps!

Thanks!

Translate
Pawan-Gupta
Level 8
Mar 15, 2021 3:33 PM UTC

Refer this post which is currently in progress - https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/can-we-async-or-defer-referencing-client-side-libraries/qaq-p/400131/comment-id/86663#M86663

 

use it for your custom libs not OOTB (until necessary)

Translate
Employee
Mar 15, 2021 1:37 PM UTC

Since these are included via the ClientLibrary Manager in AEM you can't manipulate the HTML tag used.


You could write a Sling Pipeline Transformer to add a new attribute to the tag tho, similar to [1].

 

 

[1] https://github.com/Adobe-Consulting-Services/acs-aem-commons/blob/master/bundle/src/main/java/com/adobe/acs/commons/rewriter/impl/StaticReferenceRewriteTransformerFactory.java

Translate
Rohit_Utreja
New Participant
Mar 15, 2021 1:19 PM UTC

These files are coming on the page because of client library "cq.foundation-main".

 

It seems you have created the page component by inheriting OOTB page component.

This OOTB page component has a headlibs.html file, through which this specific clienlib has been included.

 

 

You can overwrite this headlibs.html in your page component and include your project-specific clientlib in that or just leave it empty if you don't want to use it.

Translate
Bhuwan_B
New Participant
Mar 15, 2021 1:06 PM UTC

To Organize and optimize the serving of complex JavaScript and CSS code, AEM provides Client-side Library Folders, which allow you to store your client-side code in the repository, organize it into categories, and define when and how each category of code is to be served to the client. 

 

Reference : https://experienceleague.adobe.com/docs/experience-manager-65/developing/introduction/clientlibs.html?lang=en#how-client-side-libraries-work-in-aem

 

Translate