What it Does
According to the documentation:
The YUI Compressor is a Java .jar file and Java version 1.4+ is necessary to run it on your system.
Download YUI Compressor
Release 2.4.8 is available on the GitHub repository. Download and decompress the
Set Up Your Shell Script
You can use the yuijs.sh script below (also available on my GitHub repository):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
YUI_PATH variable to the actual path to your
yuicompressor-2.4.8.jar file. Save the file and use the command
chmod 744 yuijs.sh to make it executable.
Make a Bash Alias
Create an alias for your shell script so that you don’t have to type the full path to the script each time that you use it. Let’s say that you saved the
yuijs.sh file on the path
~/scripts/yuijs.sh. Open your bash startup file (either
.bashrc) and enter the following line to create the alias minijs:
To use this alias in your current shell process, use the source command on the bash startup file. Assuming that you placed this in the
.bash_profile file and your working directory contains that file, your command is:
It is not necessary to run the source command again when you close and then reopen your terminal.
Compress Your JS Files with YUI Compressor
You’re all set. Now you can use the alias in any directory. Navigate to a directory that contains one or more JS files and go to town. It works with as many files as you’d like to throw at it. The file is compressed and obfuscated, and then saved as the original file name with a
-min suffix. The original file is not modified and remains in the same directory. Hang on to the original because the obfuscated file is no longer human readable (intentionally so as to minimize file size).
Single File Example
creates the file
Multiple Files Example
creates the files
All .js Files in Working Directory