The answer to your IT questions
 

Advanced search  • Search tips
My QUESTIONS & ANSWERS
 Question:

Minify compress obfuscate javascript css ?

User Asked by: james73
Published on: 11:20/30.05.2008
Status: OPEN
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.


 Answers: 2
Sort by: /\ date | rating
Image Answer by: xpert
Posted on: 11:18/30.05.2008
Rating: 3 from possible 5 with 2 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/ubikwiki/index.php?title=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 Answer by: alexander
Posted on: 11:20/30.05.2008
Rating: 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
  
| Home | Hall of fame | Register | Log in | Terms of service | Help | Contacts |