0

I am trying to minify an html page via my Java code. I am using https://code.google.com/archive/p/htmlcompressor/ to do the compression.

Here is my method for minification :

public static String minifyHtml(String html) {
    HtmlCompressor htmlCompressor = new HtmlCompressor();
    htmlCompressor.setRemoveSurroundingSpaces(HtmlCompressor.ALL_TAGS);
    htmlCompressor.setPreserveLineBreaks(false);
    htmlCompressor.setCompressCss(true);

    return htmlCompressor.compress(document.toString());
}

However this doesn't minify the inline css that I have in the html. For example for the following tag:

<div class="content" style="font-family: Helvetica,sans-serif,Lucida Sans Unicode; font-size: 12pt; font-weight: normal; font-style: normal; text-decoration: none; color: rgb(0,0,0); background-color: transparent; margin-top: 0.0pt; margin-bottom: 0.0pt; text-indent: 0.0in; margin-left: 0.0in; margin-right: 0.0in; text-align: left; border-style: none; border-width: 0.0pt; border-color: rgb(0,0,0); padding: 0.0pt; white-space: pre-wrap;">

Can this be minified using the HtmlCompressor? If not then is there any other library that does it?

user2456373
  • 53
  • 1
  • 6

1 Answers1

1

Simple Java Replace on the string object

String html_new = html.replace(': ' , ':').replace('; ' , ';');

return html_new;