Skip navigation

Monthly Archives: Februari 2013


Since I used to work using Java before went to PHP on daily basis, I really like using Apache Ant. Actually there is a similar technology called Phing that is fully integrated with PHP, i.e. you can use a PHP code in the script. Which is good, by the way.

So recently I need to create a gzipped version to each files in a directory for the static assets. Below is the Apache Ant snippet to do that. Enjoy.

<target name="compress-assets">
    <apply executable="gzip">
        <fileset dir="${assets.dir}">
            <include name="**/*.js"/>
            <include name="**/*.css"/>
        </fileset>
        <arg value="-c" />
        <srcfile />
        <redirector>
            <outputmapper id="out" type="glob" from="*" to="${assets.dir}/*.gz"/>
        </redirector>
    </apply>
</target>

The script above basically applies Gzip executable to each JS and CSS file in the directory to their js.gz and css.gz counterpart.

Iklan
%d blogger menyukai ini: