Skip navigation


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.

2 Comments

  1. Why is it posted under “bash” ?

    Anyway, here is a bash one liner to do it

    find assetdir  \( -iname '*.js' \) -or \( -iname '*.c' \)| while read filename; do gzip -c $filename > ${filename}.gz; done
    

    Or a shorter version

    find assetdir | egrep "\.((js)|(c))$" | while read filename; do gzip -c $filename > ${filename}.gz; done
    
    • ups, kok bash yak… LOL.
      harusnya Ant.. salah klik..

      Actually I was just posting a snippet for build file using Ant. Already know the one-liner, though, since I used it when I was still using bash script for the build. But now I put most of them in the Ant file. Thanks!


Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s

%d blogger menyukai ini: