Posted on Jan 8, 2010

Javascript/CSS Minification Script

I’ve been using a little bash script I wrote that will automatically minify any Javascript and CSS files recursively in a directory with the YUI Compressor, and I thought I’d share it with the world. With the script, you can chose to minify just Javascript (with the -j option), just CSS (with the -c option), delete any existing minifed files (with the -d option), or any combination of the three. Files will be saved with a .min.js or .min.css extension (for example, test.js will become test.min.js). All you need to do is put the YUI Compressor JAR file somewhere within the current working directory, and the script will find it.

Usage is simple:

$ ./minify.sh -dcj Deleting existing minified files... Minifying JavaScript... Processing: ./test.js Minifying CSS... Processing: ./test.css Done.

You can download the latest version of the script from my GitHub repository.

blog comments powered by Disqus