Results 1 to 1 of 1
-
4th Apr 2014, 01:53 PM #1
Minify and Compress CSS & Javascript Files At a Linux/Unix Shell Prompt
You need to use "YUI Compressor" tool. It is widely used for minifying JavaScripts and stylesheets. From the project page:Tutorial details Difficulty Easy (rss) Root privileges Yes Requirements None Estimated completion time 5m
The YUI Compressor is JavaScript minifier designed to be 100% safe and yield a higher compression ratio than most other tools. Tests on the YUI Library have shown savings of over 20% compared to JSMin (becoming 10% after HTTP compression). The YUI Compressor is also able to compress CSS files by using a port of Isaac Schlueter's regular-expression-based CSS minifier.Step #1: Install JAVA on Linux or Unix
You need JAVA to run yuicompressor. See how to install JAVA on Linux:
- Install JAVA SDK on a CentOS/RHEL based system
- Instal latest JAVA SDK on a Debian/Ubuntu based system
Once Java installed on the system, make sure you can see the JDK info with the following command:
whereis java
which java
java -versio
Fig. 01: Make sure java is installed on a Linux/Unix based system
Also, make sure you set correct path to JAVA_HOME in your shell startup file. For example:
export JAVA_HOME="/usr/lib/jvm/jre-1.7.0-openjdk.x86_64"
Type the following wget command to download the latest version of yuicompressor:
$ mkdir -p $HOME/yuicompressor
$ cd !!:$
$ wget https://github.com/yui/yuicompressor...ssor-2.4.8.jar
Type the following command to run the yuicompressor directly:
$ java -jar yuicompressor-2.4.8.jar
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 <js|css> Specifies the type of the input file
--charset <charset> Read the input file using <charset>
--line-break <column> Insert a line break after the specified column number
-v, --verbose Display informational messages and warnings
-o <file> 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
JavaScript Options
--nomunge Minify only, do not obfuscate
--preserve-semi Preserve all semicolons
--disable-optimizations Disable all micro optimizations
If no input file is specified, it defaults to stdin. In this case, the 'type'
option is required. Otherwise, the 'type' option is required only if the input
file extension is neither 'js' nor 'css'.
In this example, I am going to to compress style.css code file to reduce file size and make site load faster. My current file size:
$ ls -l style.css
-rw-r--r--. 1 vivek vivek 46909 Jan 11 21:33 style.css
$ java -jar yuicompressor-2.4.8.jar --type css style.css > mini_style.css
$ java -jar yuicompressor-2.4.8.jar --type css -o mini_style.css style.css
$ ls -l style.css
-rw-r--r--. 1 vivek vivek 36576 Jan 11 21:33 mini_style.css
for i in ie.css style.css tutorial.css social.css
do
java -jar yuicompressor-2.4.8.jar --type css -o "mini_$i" "$i"
done
The syntax is:
$ java -jar yuicompressor-2.4.8.jar --type js nixcraft.js > mini_nixcraft.js
$ java -jar yuicompressor-2.4.8.jar --type js -o mini_nixcraft.js nixcraft.js
for i in nixcraft.js ads.js demo.js ui.js
do
java -jar yuicompressor-2.4.8.jar --type js -o "mini_$i" "$i"
doneGarryField Reviewed by GarryField on . Minify and Compress CSS & Javascript Files At a Linux/Unix Shell Prompt http://www.besthostingforums.com/images/cdn/besthostingforums.com/2014/04/terminal-1.png You need to use "YUI Compressor" tool. It is widely used for minifying JavaScripts and stylesheets. From the project page: Tutorial details Difficulty Rating: 5Follow Board Rules & Thread Rules.
Sponsored Links
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Similar Threads
-
HowTo: Setup SSH Keys on a Linux / Unix System
By GarryField in forum Server ManagementReplies: 0Last Post: 4th Apr 2014, 01:49 PM -
Linux/Unix: Find Command Ignore Case Insensitive Search
By GarryField in forum Server ManagementReplies: 0Last Post: 4th Apr 2014, 01:43 PM -
[Javascript] Cross-Browser page close prompt
By SplitIce in forum Webmaster ResourcesReplies: 2Last Post: 5th Dec 2010, 05:39 AM -
[linux]Rar files, upload to RS,Hotfile,fileserve,sharingmatrix then delete the files
By jpavsex in forum Tutorials and GuidesReplies: 10Last Post: 13th Jul 2010, 04:49 PM -
[off-topic] In need of a VALID Linux/UNIX VNC License for Ubuntu.
By DXS in forum General DiscussionReplies: 2Last Post: 11th Jan 2010, 11:15 PM
themaLeecher - leech and manage...
Version 4.94 released. Open older version (or...