YUI Compressor on Linux
sudo apt-get install yui-compressor
and run the commands from within our static content directory:
find . -type f -name "*.js" | while read line; do (yui-compressor --type js "$line" -o "$line"); done find . -type f -name "*.css" | while read line; do (yui-compressor --type css "$line" -o "$line"); done
In stead of doing a
find search and a
-o <file> states:
Place the output into <file>. Defaults to stdout.
Multiple files can be processed using the following syntax:
java -jar yuicompressor.jar -o '.css$:-min.css' *.css
java -jar yuicompressor.jar -o '.js$:-min.js' *.js
git clone git://github.com/mishoo/UglifyJS2.git cd UglifyJS2 npm link .
find . -type f -name "*.js" | while read line; do ( ~/dev/UglifyJS2/bin/uglifyjs "$line" -o "$line" --compress --mangle ); done
YUI Compressor on Mac OS X
Mac OS X users can use
brew to install YUI Compressor:
brew install yuicompressor
YUI Compressor on Windows
Java is required to run YUI Compressor on Windows (as it is on Linux and Mac OS X too). Download and install Java first.
- Download and unzip YUI Compressor
cmd.exe, use the following command to execute YUI Compressor:
java -jar yuicompressor-2.4.7.jar style.css -o style-min.css
The yuicompressor-2.4.7.jar file is located in the
Let’s dive more into YUI Compressor on Windows:
Suppose my website dev content is located in
E:\Data\Codebase\sites\saotn.org\www and I’ve placed YUI Compressor in
The following command compresses, or minifies, all CSS stylesheet files recursively, from within my content directory:
FOR /F %I in ('dir /b/s *.css') DO @java -jar C:\Temp\yuicompressor-2.4.7\build\yuicompressor-2.4.7.jar %I -o %I
FOR /F %I in ('dir /b/s *.js') DO @java -jar C:\Temp\yuicompressor-2.4.7\build\yuicompressor-2.4.7.jar %I -o %I
All you need to do afterwards is uploading your minified/compressed files to your website.