Include special attributes in Clientlibs(Defer, Nomodule) | Community
Skip to main content
Level 2
December 10, 2020
Solved

Include special attributes in Clientlibs(Defer, Nomodule)

  • December 10, 2020
  • 4 replies
  • 2832 views

We have a requirement to include special attributes like async, defer, nomodule to the script tags generated by client libs. We have found there is no out of the box AEM support for this. We tried to find other options. But we are only getting following github links and not getting proper steps to install these extensions. If anyone of you has done such implementation and have an idea to share, kindly let us know.

 

https://github.com/nateyolles/aem-clientlib-async

https://wcm.io/wcm/ui/clientlibs/usage.html

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by BrianKasingli

@smkswamy,

wcm.io is an Open Source project which provides libraries and extensions for AEM-based applications, very established and well known. wcm.io is widely known for it's mocking library for unit/integration. Looking at the documentation, it the client library extension tool looks very promising. Try it out, and let us know how it goes, https://wcm.io/wcm/ui/clientlibs/usage.html

4 replies

vanegi
Adobe Employee
Adobe Employee
December 10, 2020

Hi @smkswamy,

As of now, it isn’t supported in any version of AEM and as per engineering recommendation, its possible using rewriter, if the use case absolutely needs it. GRANITE-26144, GRANITE-18393 are created as an enhancement request for this feature

 

You need to create your own tag which uses the HtmlLibraryManager to get the list of includes for a particular category (or set of categories) and use those to output the appropriate HTML. One way to do this it to create a custom RequestRewriter. This essentially allows you to change what is written to the output HTML for the client lib script tag. This commons package has a code example where a request rewriter is used, and you could do something similar to rewrite the attributes for the script tag: http://adobe-consulting-services.github.io/acs-aem-commons/features/static-reference-rewriter.html.

Also see the following: https://sling.apache.org/documentation/bundles/output-rewriting-pipelines-org-apache-sling-rewriter.html

http://www.wemblog.com/2011/08/how-to-remove-html-extension-from-url.html

 

You can also check this https://github.com/nateyolles/aem-clientlib-async for reference. You can use the following to add "async" attribute: <!--/* async */--> <meta data-sly-call="${clientLib.js @ categories='your.clientlib', loading='async'}" data-sly-unwrap></meta>

 

Thanks!!

arunpatidar
Community Advisor
Community Advisor
December 11, 2020

Please check demo custom implementation to include clientlibs with defer or any other attribute

https://github.com/arunpatidar02/aem63app-repo/blob/master/java/ClientLibsModel.java

 

you can parameterize the implementation for clientlibs category, attribute(s) etc. 

Arun Patidar
BrianKasingli
Community Advisor and Adobe Champion
BrianKasingliCommunity Advisor and Adobe ChampionAccepted solution
Community Advisor and Adobe Champion
December 11, 2020

@smkswamy,

wcm.io is an Open Source project which provides libraries and extensions for AEM-based applications, very established and well known. wcm.io is widely known for it's mocking library for unit/integration. Looking at the documentation, it the client library extension tool looks very promising. Try it out, and let us know how it goes, https://wcm.io/wcm/ui/clientlibs/usage.html

Level 4
May 31, 2024

Hi,

I have installed wcm plugin in my local, still the added nonce attribute to the client libs are not showing in the viewsource.

Can someone please suggest on this?

 

 

 

shelly-goel
Adobe Employee
Adobe Employee
December 11, 2020

@smkswamy  For these additional attributes on the clientlib, there would be two steps involved:

1. Alter the HTML markup by adding additional attributes to the script and link elements

2. Since it's a custom markup, add this logic to a Pojo class to extend the behavior of HtmlLibraryManager's writeIncludes. You can define the allowed attributes as per your case like async, defer, nomodule.

 

This is detailed here: http://www.nateyolles.com/blog/2016/06/custom-aem-html5-async-clientlibs

https://github.com/nateyolles/aem-clientlib-async