Forked from magnetikonline/precompresscssjswebfont.sh
Created
August 19, 2013 19:31
-
-
Save jemerick/6273052 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# note: this won't work too well with filenames/directories with spaces in them | |
compressresource() { | |
gzip -c9 "$1" > "$1.gz" | |
touch -c --reference="$1" "$1.gz" | |
echo "Compressed: $1 > $1.gz" | |
} | |
# fetch list of websites | |
for APPDIR in `find /var/www/* -maxdepth 0` | |
do | |
# fetch all existing gzipped css/js/webfont files and remove files that do not have a base uncompressed file | |
for COMPRESSFILE in `find "$APPDIR" -type f \( -name "*.css.gz" -or -name "*.js.gz" -or -name "*.eot.gz" -or -name "*.svg.gz" -or -name "*.ttf.gz" \)` | |
do | |
if [ ! -f "`echo $COMPRESSFILE | sed -e 's/.gz$//'`" ]; then | |
# remove orphan gzipped file | |
rm "$COMPRESSFILE" | |
echo "Removed: $COMPRESSFILE" | |
fi | |
done | |
# fetch all source css/js/webfont files | |
# gzip each file and give filestamp identical to that of the uncompressed file | |
for COMPRESSFILE in `find "$APPDIR" -type f \( -name "*.css" -or -name "*.js" -or -name "*.eot" -or -name "*.svg" -or -name "*.ttf" \)` | |
do | |
if [ -f "$COMPRESSFILE.gz" ]; then | |
# only re-gzip if base file is different in timestamp to the existing gzip file | |
if [ `stat -c %Y "$COMPRESSFILE"` != `stat -c %Y "$COMPRESSFILE.gz"` ]; then | |
compressresource "$COMPRESSFILE" | |
fi | |
else | |
compressresource "$COMPRESSFILE" | |
fi | |
done | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment