[英]CQ5 Remove Render-Blocking JavaScript
I'm working on this document to remove blocking js: 我正在编写此文档以删除阻塞js:
However with CQ5 we include js via: 但是对于CQ5,我们包括js via:
<cq:includeClientLib js="headlibs"/>
How can I modify script tag like: 如何修改脚本标签,如:
<script async src="my.js">
So I can remove blocking JS. 所以我可以删除阻止JS。
The cq:includeClientLib does not have any options to do this. cq:includeClientLib没有任何选项可以执行此操作。 You can try using the com.day.cq.widget.HtmlLibraryManager interface to get the path of JS file, the tag is a is a convenience wrapper of this interface.
您可以尝试使用com.day.cq.widget.HtmlLibraryManager接口来获取JS文件的路径,该标记是一个这个界面的便利包装器。
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 takes an additional parameter minified (boolean) to give path to the minified file. 方法
getIncludePath()
还使用一个额外的参数minified (boolean)来给出缩小文件的路径。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.