Compress JS and CSS while deployement
I am using ANT to deploy build in to Tomcat Server. I Want to compress the static files CSS and JS only when i deploy to the server.
开发者_运维知识库any suggestion?
You can do something like that as part of the build (using YUI Compressor)
<target name="js.minify">
<apply executable="java" parallel="false">
<fileset dir="." includes="foo.js, bar.js"/>
<arg line="-jar"/>
<arg path="yuicompressor.jar"/>
<srcfile/>
<arg line="-o"/>
<mapper type="glob" from="*.js" to="*-min.js"/>
<targetfile/>
</apply>
</target>
<target name="css.minify">
<apply executable="java" parallel="false">
<fileset dir="." includes="*.css"/>
<arg line="-jar"/>
<arg path="yuicompressor.jar"/>
<arg line="--line-break 0"/>
<srcfile/>
<arg line="-o"/>
<mapper type="glob" from="*.css" to="*-min.css"/>
<targetfile/>
</apply>
</target>
Check out this article for more info: http://www.julienlecomte.net/blog/2007/09/16/
This blog post about using YUI compressor to minify JS/CSS using Ant might help you.
精彩评论