For web designers, publishers and developers, one cannot stress enough the importance of keeping web pages or web applications as lightweight as possible. There are various design strategies and client/server-side techniques that can be exploited to achieve this goal.
Install YUI Compressor on Linux
The YUI Compressor is written in Java, and its pre-built JAR file (as well as its source code) is available for download. Here we are going to use the JAR executable.
First, install Java run-time, which is required to run YUI Compressor.
Download and install YUI Compressor as follows.
$ sudo wget https://github.com/yui/yuicompressor/releases/download/v2.4.8/yuicompressor-2.4.8.jar -P /usr/share/java
Create a start-up script named yc, with the following content.
#!/bin/sh java -jar /usr/share/java/yuicompressor-2.4.8.jar "$@"
Now you can use yc command to launch YUI Compressor.
YUICompressor Version: 2.4.8 Usage: java -jar yuicompressor-2.4.8.jar [options] [input file] Global Options -V, --version Print version information -h, --help Displays this information --type
To compress or minify a CSS file, use the following command:
Check how much size is reduced before and after CSS compression:
756 1097 14007 default.css 0 163 5745 default-min.css
In this example, the total byte count for the original CSS file is reduced from 14KB to 5.7KB after compression.
A compressed/minified CSS file looks like the following:
Subscribe to Xmodulo
Do you want to receive Linux FAQs, detailed tutorials and tips published at Xmodulo? Enter your email address below, and we will deliver our Linux posts straight to your email box, for free. Delivery powered by Google Feedburner.