James John – Software Engineer

Minify JS & CSS Files in Linux Using YUI Compressor

YUI Compressor – Yahoo! UI Compressor is a compressing tool for minifying JS and CSS files to a small size which can improve page load of your webpage, although Yahoo! is no more maintaining the package it still work great.

Installing YUI Compressor
This package can be found in the default .DEB system repository, so all you have to do is install using the apt

$ sudo apt-get install yui-compressor

Java is needed for this package to run, so if you don’t have Java installed the apt is gonna install it together with this package

Using YUI Compressor
The usage of this package is simple, first lets minify my css. I have a CSS file named test.css and containing this:

/*
Author: Don Jajo
URL : https://donjajo.com
*/
body {
background: #000000;
color : #fff;
}

div#container {
height: 100%;
width: 100%;
}

Lets minify

$ yui-compressor --type css test.css

The output will look like this

body{background:#000;color:#fff}div#container{height:100%;width:100%}

Same as the JS file, what you need to change is –type js and it minifies it.

There is an output argument if you wish to output the return to a file  which will be like this

$ yui-compressor --type css test.css -o output.css

This is all I’ve got to know about this package, I have been trying to add it to Apache output handler to auto minify all CSS and JS files but Apache keeps returning error. Pls if you have a way….Share! 🙂

James John

Software Engineer