【发布时间】:2017-09-11 09:43:28
【问题描述】:
我正在尝试使用 Maven https://mvnrepository.com/artifact/com.googlecode.htmlcompressor/htmlcompressor/1.4 中的 html 压缩器标签库来使用 HTML 缩小
我在 pom.xml 中添加了以下依赖项
<dependency>
<groupId>com.googlecode.htmlcompressor</groupId>
<artifactId>htmlcompressor</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>com.yahoo.platform.yui</groupId>
<artifactId>yuicompressor</artifactId>
<version>2.4.6</version>
</dependency>
下面是我的 header.jsp
<%@include file="/apps/itchotelsonline/components/global.jsp"%>
<%@page import ="com.itc.hotels.services.ItcOnlineConfigurationService" %>
<%@ taglib uri="http://htmlcompressor.googlecode.com/taglib/compressor"
prefix="compress"%>
<%
ItcOnlineConfigurationService onlineConfigService = sling.getService(com.itc.hotels.services.ItcOnlineConfigurationService.class);
if(onlineConfigService != null){
String rootPagePath = onlineConfigService.getRootPagePath();
slingRequest.setAttribute("rootPagePath",rootPagePath);
}
%>
<compress:html removeIntertagSpaces="true" enabled="true" removeComments="false" compressJavaScript="true" yuiJsDisableOptimizations="true">
<cq:include path="${rootPagePath}/jcr:content/header" resourceType="itchotelsonline/components/content/header"/>
<div class="modal fade in new-modal" id="loginOverlayPopup" tabindex="-1" role="dialog" aria-labelledby="" aria-hidden="true" style="display: none;">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-body text-center">
<center>
<p><strong id="loginInactivityPopUp"> You are Logged Out due to Inactivity! </strong></p>
</center>
<div class="clear"></div>
<div class="newBook clearfix">
<button type="button" class="btn btn-default" id="loginInactivityBtn" data-dismiss="modal" onclick="resetLoginInactivityPopUp();">Close</button>
</div>
</div>
</div>
</div>
</div>
我在其中添加了 compress html 行和 taglibs。
<%@ taglib uri="http://htmlcompressor.googlecode.com/taglib/compressor"
prefix="compress"%>
<compress:html removeIntertagSpaces="true" enabled="true" removeComments="false" compressJavaScript="true" yuiJsDisableOptimizations="true">
下面是我的footer.jsp
<%@include file="/apps/itchotelsonline/components/global.jsp"%>
<%@page import ="com.itc.hotels.services.ItcOnlineConfigurationService" %>
<%
ItcOnlineConfigurationService onlineConfigService = sling.getService(com.itc.hotels.services.ItcOnlineConfigurationService.class);
if(onlineConfigService != null){
String rootPagePath = onlineConfigService.getRootPagePath();
pageContext.setAttribute("rootPagePath",rootPagePath);
}
%>
<cq:include path="${rootPagePath}/jcr:content/footer" resourceType="itchotelsonline/components/content/footer"/>
</compress:html>
我在这结束了。
在给 maven build clean install 之后,我收到以下错误
org.apache.sling.scripting.jsp.jasper.JasperException: 绝对 uri:http://htmlcompressor.googlecode.com/taglib/compressor 无法在 web.xml 或随此应用程序部署的 jar 文件中解析 在 org.apache.sling.scripting.jsp.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:51)
我尝试重新启动 AEM 实例并刷新捆绑包,但仍未解决此问题。 我正在尝试在我的 AEM 网站上实现 HTML 缩小。我检查了 Day CQ HTML 库管理器,但它只压缩 CSS 和 JS,而不压缩通过 AEM 中的 JSP 呈现的 HTML。 AEM 中是否有可以使用的替代方法,或者可以使用 html 压缩器而不会出现上述错误? 请提前建议和感谢。
****新编辑******
我将库作为 OSGI 包导入,但现在它引发了类型转换异常。我发现 htmlcompressor 不压缩 jsps,但需要纯 html 进行压缩,页面速度模块是一个可能的替代方案,但 CSS 和 JS 已经被缩小了Day CQ HTML 库管理器,我们还通过更改 httpd.conf 中的缓存配置来利用浏览器缓存。我唯一的要求是真的缩小 HTML。是否有任何库可以与 AEM 集成并用于相同的用途?
【问题讨论】: