Aditya Auradkar
Aditya Auradkar

Reputation: 11

html minification in AEM 6.0

I am trying to use HTML minification using the html compressor tag library in Maven https://mvnrepository.com/artifact/com.googlecode.htmlcompressor/htmlcompressor/1.4

i added the below dependencies to 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>

Below is my 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>

In it i added the compress html lines and the taglibs.

<%@ taglib uri="http://htmlcompressor.googlecode.com/taglib/compressor"
    prefix="compress"%>
<compress:html removeIntertagSpaces="true" enabled="true" removeComments="false" compressJavaScript="true" yuiJsDisableOptimizations="true">

Below is my 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>

I ended the in this.

After giving maven build clean install i am getting the below error

org.apache.sling.scripting.jsp.jasper.JasperException: The absolute uri: http://htmlcompressor.googlecode.com/taglib/compressor cannot be resolved in either web.xml or the jar files deployed with this application at org.apache.sling.scripting.jsp.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:51)

I tried restarting the AEM instance and refreshing the bundles but that has not resolved this issue. I am trying to implement HTML minification on my AEM website. I have checked out the Day CQ HTML Library Manager but it only compresses the CSS and JS and not HTML which gets rendered through JSP in AEM. Is there an alternate method in AEM which can be used or can the html compressor be used without getting the above error? Please suggest and thanks in advance.

****New Edit******

I imported the library as OSGI bundle but now it threw a typecast exception.I found that htmlcompressor is not compressing jsps but needs pure html for compression,The page speed mod is a possible alternative but CSS and JS has already been minified by Day CQ HTML Library Manager and we are also leveraging browser caching by changing caching configuration in httpd.conf. My only requirement is HTML minification really.Is there any library that can be integrated with AEM and used for the same?

Upvotes: 0

Views: 1275

Answers (1)

mickleroy
mickleroy

Reputation: 1008

The absolute uri: http://htmlcompressor.googlecode.com/taglib/compressor cannot be resolved in either web.xml or the jar files deployed with this application

Check that the htmlcompressor taglib is present in http://localhost:4502/system/console/status-jsptaglibs. It looks like the HTML compressor JAR is not an OSGi bunde or you haven't imported it properly into your project. You can't just add a Maven dependency and expect any JAR to work in an OSGI container but I won't cover this here as there is plenty of information out there.

Compressing HTML using a tag library doesn't sound ideal to me. In my opinion you'd be better off installing a module like Google mod_pagespeed on the web server sitting in front of your AEM instance.

It will save you the hassle of having to specify that tag in your code and will also perform much more thorough optimizations of the rendered markup (including inlining Javascript, etc).

Upvotes: 2

Related Questions