내 커뮤니티 업적 표시줄을 확대합니다.

Submissions are now open for the 2026 Adobe Experience Maker Awards.
해결됨

Minify HTML ins AEM 6.5

Avatar

Level 3

Hi Guys,
I want to minify HTML in my project. When I do view source code for page ,in the HTML generated, I can see lot of whitespace. I need a way to minify the HTML files (in a way that after minifcation , the size of the HTML should be 30% less than original HTML file.)

note: The scenario mentioned in bracket is secondary, Primary aim is to minify the HTML files
(screenshot below)
adi411_0-1719926855309.png


Thank You,
Aditya Srivastava

주제

토픽은 커뮤니티 콘텐츠를 분류하여 관련성 있는 콘텐츠를 찾는 데 도움이 됩니다.

1 채택된 해결책 개

Avatar

정확한 답변 작성자:
Community Advisor and Adobe Champion

@adi411 - I believe you are doing email development in AEM and sending the HTML to comms platform.

 

The comms platform can request the AEM page by calling a custom servlet. In the servlet you can then do HttpGet of the page path (which is requested) and the compress and send as response.

 

You need to add maven dependency for html compressor:

<dependency>
    <groupId>com.googlecode.htmlcompressor</groupId>
    <artifactId>htmlcompressor</artifactId>
    <version>1.5.3</version>
    <scope>provided</scope>
</dependency>

 

원본 게시물의 솔루션 보기

7 답변 개

Avatar

Community Advisor

Avatar

Community Advisor and Adobe Champion

Hi, 

Please check this blog which explains how to enable the mod_deflate from Apache (dispatcher) https://www.albinsblog.com/2018/09/improve-performance-of-adobe-experience.html which is responsible for compressing other types of documents.

Also check the official documentation about the same: https://experienceleague.adobe.com/en/docs/experience-manager-dispatcher/using/configuring/dispatche... 


Hope this helps



Esteban Bustamante

Avatar

Community Advisor and Adobe Champion

@adi411 - While compression can be achived from Dispatcher by enabling gzip as mentioned by others using Apache Dispatcher modules. One other way is to use HTML Compression libraries which gives you flexibility to remove whitespaces, clean CSS, etc.

Check Google's HTML Compressor Java library - https://code.google.com/archive/p/htmlcompressor/

 

A custom servlet can be written to produce the output:

HttpGet httpGet = new HttpGet(url);
HttpResponse httpResponse = httpClient.execute(httpGet);
String output = httpResponse.getEntity().toString()

HtmlCompressor compressor = new HtmlCompressor();
String compressedHtml = compressor.compress(html);

response.setContentType(ContentType.TEXT_HTML.getMimeType());
response.setStatus(HttpStatus.SC_OK);
response.getWriter().write(compressedHtml);

 

Avatar

Level 3

Hi @Jineet_Vora  - Can you explain a bit more on the custom servlet part?

 https://code.google.com/archive/p/htmlcompressor/  --> I visited this link and there I found Maven Integration section, but how to use it  those links result in  404.

Avatar

정확한 답변 작성자:
Community Advisor and Adobe Champion

@adi411 - I believe you are doing email development in AEM and sending the HTML to comms platform.

 

The comms platform can request the AEM page by calling a custom servlet. In the servlet you can then do HttpGet of the page path (which is requested) and the compress and send as response.

 

You need to add maven dependency for html compressor:

<dependency>
    <groupId>com.googlecode.htmlcompressor</groupId>
    <artifactId>htmlcompressor</artifactId>
    <version>1.5.3</version>
    <scope>provided</scope>
</dependency>

 

Avatar

Community Advisor

@adi411 

In addition to responses shared by others, In case if you are using CDN such as Cloudflare / Akamai

You can try to enable HTML minification in CDN configuration

https://developers.cloudflare.com/speed/optimization/content/auto-minify/

 


Amanath Ullah

Avatar

Community Advisor

Hi @adi411 
What are the reasons for minifying HTML? What benefits you are targeting? If the goal is solely to deliver faster content to end users, you can use Gzip compression?

Gzip compression works by compressing the files on the server side and decompressing them on the client side, further reducing load times and improving user experience.
https://blog.hubspot.com/website/gzip-compression 

 

Arun Patidar

AEM LinksLinkedIn