4
YUI Compressor
Calvin Xiao edited this page 2014-01-27 22:01:49 -08:00
This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

YUICompressor可以压缩CSS和JavaScript文件顺便还能混乱里面的符号。

相关参数可以看这里它的README ,比如多少字符之后还是换一下行啦,只压缩不混乱啦。

Springside的showcase里用命令行简单的调用

java -jar yuicompressor-*.jar -o ..\src\main\webapp\static\showcase.min.css ..\src\main\webapp\static\showcase.css

可惜它那个批量转换一批文件的语法,但*.css的语法在Windows机器上不支持。在Linux上自动将一批*.css转换成*-min.css

  java -jar yuicompressor-*.jar -o '.css$:-min.css' *.css

另外有一个更牛的wro4j项目不但可以基于YUICompressor压缩文件还可以将多个js/css文件组合成一个大文件(开发时分成多个文件便于管理,上线后客户访问时组合成一个减少交互次数),还支持编译时(Maven)和运行时执行。