yui-logo.pngThe YUI Compressor is JavaScript and CSS minifier designed to be 100% safe and yield a higher compression ratio than most other tools.

  1. First of all you should download latest version of yuicompressor
  2. If you want to run it in eclipse with ant,you need ant-task
  3. You should edit your ant build.xml file, and add this lines of code:

<project name="test">
<property name="web.dir" value="WebContent"/>
    <property name="input.dir" value="${web.dir}/js"/>
    <property name="output.dir" value="${web.dir}/jscompressed"/>
   
    <target name="clean_compressed_js" description="Clean output directories">
            <delete>
                <fileset dir="${output.dir}">
                    <include name="*.js"/>
                </fileset>
            </delete>
        </target>
    
    <taskdef name="yuicompress" classname="net.noha.tools.ant.yuicompressor.tasks.YuiCompressorTask">
        <classpath>
            <pathelement path="${web.dir}/WEB-INF/lib/yuicompressor-2.4.7.jar" />
            <pathelement path="${web.dir}/WEB-INF/lib/yui-compressor-ant-task-0.5.jar" />
            <pathelement path="${web.dir}/WEB-INF/lib/rhino-1.6R7.jar" />

        </classpath>
    </taskdef>  
   

    <target name="compress_javascript" depends="clean_compressed_js">
        <echo>Compressing files</echo>
        <yuicompress munge="yes"  preserveallsemicolons="yes" toDir="${output.dir}" fromDir="${input.dir}" csssuffix=".css" jssuffix=".js" >
                <include name="*.js"/>
        </yuicompress>
    </target>
</project>
PS: Next step should be creating gzip archive, if your server support it

References:
http://developer.yahoo.com/yui/compressor/
http://webo.in/articles/habrahabr/112-minify-combine-javascript-troubles/
Also tools for testing your web-site speed, with recommendations: 
http://loads.in/
http://tools.pingdom.com/
http://gtmetrix.com/
https://developers.google.com/pagespeed/