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)
Thank You,
Aditya Srivastava
Solved! Go to Solution.
Topics help categorize Community content and increase your ability to discover relevant content.
Views
Replies
Total Likes
@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>
Hi @adi411 ,
Please have a look https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/compress-minify-the-html-p...
Thanks,
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
@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);
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.
@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>
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/
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
Views
Likes
Replies
Views
Likes
Replies