Compiling and Using JSMin on Ubuntu
Brian Dailey is a LAMP-stack developer with a wide range of experience in the development world. Get in touch!
For more articles on the development trade, see the Blog.
JSMin is a popular Javascript minifier that you will need to compile from the C source code on Ubuntu to use. (An executable is already available for Windows). I use it often for compressing jQuery extensions.
First, download the jsmin.c file into a directory.
$ cd $ mkdir jsmin $ cd !$ $ wget http://www.crockford.com/javascript/jsmin.c
For the next step you'll need to make sure you install the gcc compilers for Ubuntu, if you have not already done this.
$ sudo apt-get install gcc
Compile the file.
$ cc jsmin.c -o jsmin
You can leave the compiled file in your home directory, but if you think you're going to keep it around I suggest moving it to /usr/local/lib/jsmin/ and creating a symbolic link from /usr/local/bin/
$ sudo mv ~/jsmin/ /usr/local/lib/jsmin/ && \
sudo ln -s /usr/local/lib/jsmin/jsmin /usr/local/bin/jsmin
Now, to use it! The below assumes you haven't moved it from your home directory. If you have, then the ~/jsmin/ path is unnecessary.
$ ~/jsmin/jsmin < my_javascript.src.js > my_javascript.min.js
That's pretty much all there is to it.