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);
}
网友评论