【问题标题】:How to minify inline css in an html using HtmlCompressor?如何使用 HtmlCompressor 缩小 html 中的内联 css?
【发布时间】:2016-06-03 21:33:17
【问题描述】:

我正在尝试通过我的 Java 代码缩小 html 页面。我正在使用https://code.google.com/archive/p/htmlcompressor/ 进行压缩。

这是我的缩小方法:

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());
}

但是,这并没有缩小我在 html 中的内联 css。 例如以下标签:

<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;">

这可以使用 HtmlCompressor 缩小吗?如果没有,那么还有其他图书馆可以做到吗?

【问题讨论】:

    标签: java html html-parsing minify html-compression


    【解决方案1】:

    字符串对象上的简单 Java 替换

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-29
      • 2023-02-18
      • 1970-01-01
      • 1970-01-01
      • 2022-01-19
      • 1970-01-01
      相关资源
      最近更新 更多