sudo apt-get install optipng 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 find . -type f -name "*.png" | while read line; do (optipng -o5 "$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
Install UglifyJS 2 from Git
The easiest way is to git clone UglifyJS:
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
Mac OS X users can use
brew to install YUI Compressor:
brew install yuicompressor
And compile OptiPNG from source:
- Download the compressed source code
- Open the file, optipng-0.7.5.tar.gz in the Finder. It will create a folder called optipng-0.7.5
- Open the Terminal, found under Applications -> Utilities
- In the Terminal, type
cdthen drag the optipng-0.7.5 folder into the Terminal, and press Return on the keyboard. This puts you inside that directory
./configureand press Return
sudo make installand press Return
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
- Using 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
Suppose my website dev content is located in
E:\Data\Codebase\sites\saotn.org\www and I’ve placed YUI Compressor and OptiPNG in
The following command lossless compresses all PNG files recursively, from within my content directory:
FOR /F %I in ('dir /b/s *.png') DO @C:\Temp\optipng-0.7.5-win32\optipng.exe -o5 %I
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
My name is Jan. I am not a hacker, coder, developer or guru. I am merely a systems administrator, doing my daily thing at Vevida.
If you feel a post has helped solve your problem, or has saved you time, please consider making a donation. You can transfer a direct donation through Paypal or via bank wire-transfer IBAN: NL31 ABNA 0432217258 (Jan Reilink). Thanks!