本文介绍了CQ5删除渲染 - 拦截JavaScript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我工作的这个文件删除阻止JS:
I'm working on this document to remove blocking js:
然而,随着CQ5我们有通过JS:
However with CQ5 we include js via:
<cq:includeClientLib js="headlibs"/>
我如何修改脚本标签,如:
How can I modify script tag like:
<script async src="my.js">
这样我就可以去除阻塞JS。
So I can remove blocking JS.
推荐答案
的的没有任何选项来做到这一点。您可以尝试使用融为一体。 day.cq.widget.HtmlLibraryManager 接口获取JS文件的路径,标签是为这个接口的方便包装。
The cq:includeClientLib does not have any options to do this. 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 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");
}
方法 getIncludePath()
还需要一个额外的参数缩小的(布尔)给予路径minified的文件。
The method getIncludePath()
also takes an additional parameter minified (boolean) to give path to the minified file.
这篇关于CQ5删除渲染 - 拦截JavaScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!