in Advanced 

Question preview

HomeQuestion preview:
Log in

Minify compress obfuscate javascript css ?

In build process for a site with ANT is it possible to integrate some task to compress javascript and CSS files?

If you know some tool or ant task, please write your solutions for this. Minifying Javascript will generate less traffic for enduser of the site and will optimize overall performance. Actually, I just analyze response headers and content with another excellent tool - Firebug. In the phase when application had been optimized against almost all possible bottlenecks, I decided to use a sort of compression (but not gzip) of resource files (js, css) based on their structure.


Do you know someone who could answer? Ask him for help
Answers: 2
Sort by: date rating
image xpert
14:18/30.05.2008
3.7 from possible 5 with 3 votes
You can download libraries yuicompressor-2.3.4.jar from http://www.julienlecomte.net/yuicompressor/
and YUIAnt.jar from http://www.ubik-ingenierie.com/ubikw...itle=Minifying_JS/CSS

and in your ant build file you can make target like this :

    <target name="minify-js-css" description="Minifiy a set of files">
        <taskdef name="yuicompress" classname="com.yahoo.platform.yui.compressor.YUICompressTask">
            <classpath>
                <path refid="yuicompressor.classpath"/>
            </classpath>
        </taskdef>

        <mkdir dir="out_js_folder" />
        <mkdir dir="out_css_folder" />
        <yuicompress linebreak="400" warn="false" munge="no" preserveallsemicolons="true"
            outputfolder="out_js_folder" >
            <fileset dir="in_js_folder" >
                <include name="**/*.js" />
            </fileset>
        </yuicompress>
        <yuicompress linebreak="300" warn="false" munge="no" preserveallsemicolons="true"
            outputfolder="out_css_folder" >
            <fileset dir="in_css_folder" >
                <include name="**/*.css" />
            </fileset>
        </yuicompress>
    </target>


This code can minify(compress, minimize size) and obfuscate your Javascript (JS) files and your cascade style sheet (CSS) files. You can integrate this into your continious build as ANT task. Easy and suitable, istn't it!?
Vote:
image alexander
14:20/30.05.2008
3 from possible 5 with 2 votes
For javascript i am using http://javascriptcompressor.com But for css most of the optimizers are buggy so you have to test them first.
Vote:
Please vote! Your opinion matters!
If you haven't found what you've looking for, post a question
Ask question
Related questions:
| Home | Hall of fame | Registration | Log in | Terms of service | Privacy policy | Help | Contacts | RSS |