CQ5 Remove JavaScript blocking JavaScript
1 answer
cq: includeClientLib doesn't have any options for this. You can try using the com.day.cq.widget.HtmlLibraryManager interface to get the path to the JS file, the tag is a convenient wrapper around this interface.
com.day.cq.widget.HtmlLibraryManager clientlibmanager = sling.getService(com.day.cq.widget.HtmlLibraryManager.class);
if(clientlibmanager != null)
{
String[] categoryArray = {"headlibs"};
java.util.Collection<com.day.cq.widget.ClientLibrary> libs = clientlibmanager.getLibraries(catArray,com.day.cq.widget.LibraryType.JS,false,false);
for(com.day.cq.widget.ClientLibrary lib : libs) {
out.write("<script async type=\"text/javascript\" src=\""+lib.getIncludePath(com.day.cq.widget.LibraryType.JS)+"\"></script>");
}
} else {
out.write("clientlib manager is null");
}
The method getIncludePath()
also accepts an additional parameter minified (boolean) to specify the path to the minified file.
+4
source to share