美文网首页
java中对html文件内容压缩

java中对html文件内容压缩

作者: 星钻首席小管家 | 来源:发表于2021-07-30 16:05 被阅读0次

    1.依赖

            <dependency>
                <groupId>com.googlecode.htmlcompressor</groupId>
                <artifactId>htmlcompressor</artifactId>
                <version>1.5.2</version>
            </dependency>
            <dependency>
                <groupId>com.yahoo.platform.yui</groupId>
                <artifactId>yuicompressor</artifactId>
                <version>2.4.8</version>
            </dependency>
    

    2.使用方法

         /**
         * 压缩html
         * @param text
         * @return
         */
        private String htmlCompress(String text) {
            HtmlCompressor compressor = new HtmlCompressor();
            compressor.setEnabled(true);
            compressor.setCompressCss(true);
            compressor.setYuiJsPreserveAllSemiColons(true);
            compressor.setYuiJsLineBreak(1);
            compressor.setPreserveLineBreaks(false);
            compressor.setRemoveIntertagSpaces(true);
            compressor.setRemoveComments(true);
            compressor.setRemoveMultiSpaces(true);
            compressor.setCompressJavaScript(true);
            return compressor.compress(text);
        }
    

    相关文章

      网友评论

          本文标题:java中对html文件内容压缩

          本文链接:https://www.haomeiwen.com/subject/usdgmltx.html