My last scripting related article has long been gone. So today just a short one, nothing special but a handy tool. Today most pages use CSS Stylesheets to define the layout and design time to time those CSS files are getting huge, bigger than the actual webpage HTML. There are several ways to “minify” / “compress” them. A Browser dont need the comments or linebreaks to interpret a code. But that`s all for the basics. One of the most used Tools is the YUI-compressor wich is a JAVA based JS & CSS Compression tool. I use a small bash script to process all my webpage CSS files with this compressor. It simple compress all CSS files in the current folder and output the saved bytes.

echo Compressing CSS Files...
for f in `find -name "*.css" -not -name "*.min.css"`;
	echo "\t- "$f to $target
	FILESIZE=$(stat -c%s "$f")
	yui-compressor --type css --nomunge -o $target $f
	FILESIZEC=$(stat -c%s "$target")
	saved=$(($saved + $diff))
	echo "\t  $diff bytes saved"
echo "Done ! Total saved: $saved bytes"
chown www-data.www-data *.min.css

This is how the output looks like for CSS of this page:
use YUI Compressor to compress a whole folder

Free to use, improvements welcomed.

bitcoin Icon This page does not contain ads! If you find it usefull, feel free to send me some Support via Bitcoin.
✉ Marco Götze//