Skip to content

Commit

Permalink
Add "GZIP" feature.
Browse files Browse the repository at this point in the history
  • Loading branch information
Arthur Furlan committed Oct 10, 2012
1 parent 09a146c commit 66f6a0e
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion src/minify.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

YUICOMPRESSOR="yuicompressor.jar"
GOOGLECLOSURE="googleclosure.jar"
GZIP="1"

if [ $# -lt 1 ]; then
echo "Usage: $0 BASEDIR"
Expand Down Expand Up @@ -45,6 +46,20 @@ is_file_minified() {
fi
}

## check if the file should be statically gziped
gzip_compressor() {
[ $# -lt 1 ] && return 0

FILE="$1"
DEST="${FILE}.gz"

## check if this feature is enabled
if [ "$GZIP" = "1" ]; then
gzip -c "${FILE}" > "${DEST}"
touch "${DEST}" -r "${FILE}"
fi
}

## minify all modified files under $BASEDIR
BASEDIR=$1
find "$BASEDIR" -type f | egrep -v '\.min\.' | while read FILE; do
Expand All @@ -68,6 +83,9 @@ find "$BASEDIR" -type f | egrep -v '\.min\.' | while read FILE; do
## check if the minified file really is smaller
is_file_minified "$FILE" "$DEST"
[ "$?" = "0" ] || cp "$FILE" "$DEST"

## check if the file should be also compressed using gzip
gzip_compressor "$DEST"
;;

css)
Expand All @@ -84,6 +102,9 @@ find "$BASEDIR" -type f | egrep -v '\.min\.' | while read FILE; do
## check if the minified file really is smaller
is_file_minified "$FILE" "$DEST"
[ "$?" = "0" ] || cp "$FILE" "$DEST"

## check if the file should be also compressed using gzip
gzip_compressor "$DEST"
;;

less)
Expand All @@ -95,13 +116,16 @@ find "$BASEDIR" -type f | egrep -v '\.min\.' | while read FILE; do

## create the new (and minified) version
echo "Compressing: ${DEST}"
lessc "${FILE}" --yui-compress > "${TEMP}"
lessc "${FILE}" --yui-compress > "${DEST}"

## less files cannot use the same rule of copying
## the original file over the destination file if
## the minified version was bigger than the original
## because the less syntax could not be a valid css
## syntax

## check if the file should be also compressed using gzip
gzip_compressor "$DEST"
;;

png)
Expand All @@ -120,6 +144,9 @@ find "$BASEDIR" -type f | egrep -v '\.min\.' | while read FILE; do
## check if the minified file really is smaller
is_file_minified "$FILE" "$DEST"
[ "$?" = "0" ] || cp "$FILE" "$DEST"

## check if the file should be also compressed using gzip
gzip_compressor "$DEST"
;;

jpg|jpeg)
Expand All @@ -137,6 +164,9 @@ find "$BASEDIR" -type f | egrep -v '\.min\.' | while read FILE; do
## check if the minified file really is smaller
is_file_minified "$FILE" "$DEST"
[ "$?" = "0" ] || cp "$FILE" "$DEST"

## check if the file should be also compressed using gzip
gzip_compressor "$DEST"
;;

gif)
Expand All @@ -153,6 +183,9 @@ find "$BASEDIR" -type f | egrep -v '\.min\.' | while read FILE; do
## check if the minified file really is smaller
is_file_minified "$FILE" "$DEST"
[ "$?" = "0" ] || cp "$FILE" "$DEST"

## check if the file should be also compressed using gzip
gzip_compressor "$DEST"
;;

xml)
Expand Down

0 comments on commit 66f6a0e

Please sign in to comment.