Sunday, February 27, 2011: Shell Script: Testing Gzip « from the old blog archive »

I found this old shell script I have written long time ago. I called it httpgztest.

NOGZ=`wget "$1" -q -O- | wc -c`
echo "Without gzip:       $NOGZ"
YESGZ=`wget --header="Accept-Encoding: gzip, deflate" "$1" -q -O- | wc -c`
echo "With gzip:          $YESGZ"
RATIO=`echo "scale=3;$YESGZ/$NOGZ" | bc`
echo "Compression ratio:  $RATIO"
if [ $YESGZ -ge $NOGZ ]; then
    echo "Gzip is not enabled for this URL. Go check."

To use it, run it, passing URL as the argument


and it shows the compression ratio.

Without gzip:       79851
With gzip:          20839
Compression ratio:  .260

And if the first and the second number are the same, i.e., the compression ratio is 1, then your gzip is not working.

Without gzip:       1820
With gzip:          1820
Compression ratio:  1.000