Javascript Compression — Tools and Process

This article is a review of the tools and processes that I have tested and gives plusses and minuses of each.

Software Uncompressed Compressed Percent Comment
Closure Compiler 39K 16K 59% with ADVANCED_OPTIMIZATIONS
YUI Compressor 39K 22K 44%
perl-Javascript-Minifier 39K 25K 36%

 

perl-Javascript-Minifier
Since CPAN library’s Javascript-Minifier and CSS-Minifier are immediately available linux tools they are a good starting point. The Javascript-Minifier is simple to use. Here is a script that you can try to see how it works:

#!/usr/bin/perl
 use JavaScript::Minifier qw(minify);
 my($iFile)=$ARGV[0];
 my($oFile)=$iFile;
 $oFile=~ s/[.]js//;
 $oFile="${oFile}_perl_min.js";
 open(INFILE, "$iFile") or die;
 open(OUTFILE, ">$oFile") or die;
 minify(input => *INFILE, outfile => *OUTFILE);
 close(INFILE);
 close(OUTFILE);

In my tests, it didn’t break my code, but did generate errors because of incorrectnesses in my code. I used the google chrome jslint plugin to find the errors. jslint only works on pure javascript, but strings are not parsed. Thus you can use php to initialize variables by putting the php code inside of quotes, and still check it with jslint.

 

YUI Compressor
The YUI Compressor is Yahoo’s library, and works better than perl-Javascript-Minifier. Here is an example command for using YUI Compressor:

java -jar yuicompressor-2.4.7.jar --type js -o filename_yui_min.js filename.js

A nice feature of the yuicompressor is that it can accept javascript strings from the command line. This makes it simple to script. It’s goal is to not break code, and in my tests this was observed to be true.

 

Closure Compiler
The google closure compiler is the most advanced of the ones that I tested. It has a simple mode that doesn’t break code and an option for ADVANCED_OPTIMIZATIONS that produces very compressed code. Here is an example command for using the closure compiler in simple mode:

java -jar compiler.jar --js filename.js --js_output_file filename_closure_min.js --externs externs.js

And similarly for advanced mode:

java -jar compiler.jar --compilation_level ADVANCED_OPTIMIZATIONS --js filename.js --js_output_file filename_closure_min.js --externs exterms.js

Similar to perl-Javascript-Minifier, closure compiler only works on pure javascript files. Because of the effectiveness of the optimizations that it does, it can break code. To effectively use it, you need to design your javascript with minification in mind. Typically you want to use your javascript as a library (i.e. as handers for events such as mouse clicks) to do this, you need to add a small amount of code that preserves the function names that will be available to external scripts. Similarly if you want to use external libraries in your library, you need to add extern declarations that will preserve the external symbols. There are less modifications required if you use the simple mode than for the advanced mode. I wanted to use advanced mode for some script that contains jQuery calls (including jQuery Mobile), but wasn’t able to find a way to preserve the jQuery and $ symbols. I tried using –externs with the externs file available as an addon from google svn, but this didn’t solve the problem. Therefore I recommend using simple mode for files containing jQuery and advanced mode for files that do not.

 

In summary of the tools reviewed google closure compiler is the most effective, perl-Javascript-Minifier is the least likely to break code, and yuicompressor is a compromise between these extremes. Additionally each of these tools can be run locally on your machine.

TWiki for a dynamic Company Operations Manual

This article is an overview of the TWiki system with an emphasis on usage as an intranet and Company Operations Manual. A small business can benefit by having such a system in several ways :

  • share knowledge and overlap responsibilities
  • document experience and improve processes
  • identify and facilitate process automation

A Company Operations Manual seeks to codify the processes that the company’s operation depends upon. It must

  • be simple to use/extend
  • be easy to navigate
  • have properties that facilitate improvement and revision
  • allow compartmentalization

TWiki fits each of these needs abundantly. It is by nature a system designed for ease of input. Concepts such as WikiWords and WebNotify allow for quick navigation by facilitating linkages among the various processes and automatically prompting personnel when processes of interest are updated. There are plugins that can keep statistics on how frequently topics are used. This allows identification of processes that would be good candidates for automation (high usage) and those that could be improved or deleted (low usage). TWiki also has built-in support for access control via group membership. This coupled with good design can simply the process of restricting auditors, contractors, and guests to areas of their focus, expertise, or clearance.

In small business there are fewer hands, and the processes and policys must be correspondingly light-weight. A dynamic, intranet-based Company Operations Manual is one way to achieve this necessary business requirement.

Linux PDF Virtual Printer

Use cups-pdf as a Linux PDF virtual printer

Recently a constituent of mine asked for some help getting her Linux distro to print to PDF.  In her case she was using the photo sharing software Picasa by Google and needed the ability to print her pictures to pdf files.  Unlike open office which will create pdf files Picasa was looking for a linux pdf virtual printer to print to.  After some searching I found that installing cups-pdf would enable linux to print to a virtual cups-pdf printer that appeared as a printer device on the system.  This process worked perfectly with Picasa and quickly generated a pdf on my desktop of any picture I selected to print.

How to install it:

Installing cups-pdf was easy.  In my case I was using Fedora core 12 with its standard repositories as well as the rpm-fusion repositories.  All I had to do was open the package manager, search for cups-pdf, and install it.  Once it was installed I checked to see if the virtual device showed up in the administration-printing menu which it did and I was able to use it with no configuration required.  If you are using a different linux distribution this process should work for you, but you may need to find and install a repository with the cups-pdf.

I hope this helps someone looking for a linux pdf virtual printer.

If you’ve had an experience with this or need help the please comment here and contact me.

– Joel

Fedora 12 and The Wacom Bamboo Pen CTL-460 tablet

Recently I received the gift of a Wacom Bamboo Pen CTL-460 tablet.  I’ve been wanting one of these for quite some time and I was excited to get it.  I’m no artist, but there have been times that I wanted a device like this so I could draw a quick sketch or cartoon type image and use it without worrying about infringing on someones copyrighting.  This device will enable me to do that.

Wacom Bamboo Pen CTL-460 Tablet
Running on Fedora 12

The Wacom Bamboo Pen CTL-460 tablet does not come with any out of the box linux support and so I had to do a little research to get it running on my Fedora 12 laptop.  After searching around for a while I found the following set of instructions at http://groups.google.com/group/eeelinux/web/f13-wacom-ct-460-tablet-get-it-working-quickly After tinkering around with the packages in the instructions which are located at http://sourceforge.net/projects/linuxwacom/files/.  I was able to get the tablet working.

I’m not an artist, but hopefully the drawings I’ll be able to produce will and enliven this blog a little.   So far I’m using it with GIMP.  I will say that the use of the tablet is very different from using a mouse.  With a mouse all activity is relative to your current cursor position on the screen, but with the tablet your positioning is relative to the X, Y coordinates on the writing surface.

– Joel

Using the Olympus Digital Voice Recorder with Linux

The Olympus Digital Voice Recorder model VN-960PC does not come with any linux support whatsoever. You may install the software that comes with the unit using Wine, but it still will not be able to get files from the device using the usb cable.

Fortunately there is an open source solution to this problem. ODVR is hosted on Google and can be found here: http://code.google.com/p/odvr/.

The project was developed for the Ubuntu environment, but I’ve found that it was easy to install it on other distributions by:

download the source code,

review the instructions in the readme,

install the needed dependencies libraries using yum,

compile and install the software.

I compiled this on Fedora 12 and placed a launcher for it on my desktop. I use it with audacity to do audio mixing. It works great.

Here’s the link should you desire to install this on a fedora machine: http://aboutfedora.blogspot.com/2010/12/using-odvr-for-olympus-digital-voice.html

Contact me if you have any questions or comments.

– Joel

If you’re installing this on an ubuntu based machine or would like to talk to someone elses who has used this software with other Olympus devices go here: http://www.piotrkrzyzek.com/olympus-vn-480pc-working-in-linux-odvr

Replacing Windows – And Saving Money

A couple years ago I set out to totally replace Windows as my operating system of choice. I wanted to use Linux and open source software for everything I needed on the PC. Two years later I’m happy to announce that I’ve mostly reached that goal with the exception of tax preparation software, I’m using Linux and open source software for the following tasks.

Word Processing: Open Office

Spreadsheets: Open Office Database: Mysql, phpmyadmin

Web Browsing: Firefox, Opera, Google Chrome and others.

Email: Thunderbird Audio Processing: Audacity

Audio Ripping: VLC

Video Viewing: Adobe Flash, VLC, Xine, Media Player

Software Development – Web Development: NetBeans IDE, Eclipse, Cssed and others.

Remote Desktop: Gnome-RDP, Tight-VNC Viewer, SSH

Remote Administration: Webmin

Gaming: SpringLobby – RTS, PlaneShift – RPG

This list is far from complete. I’ve found that no matter what the task or objective, with a little research, I can find an open source project that other people in the community are working on and use it to solve my problems. I can’t imagine ever going back to Windows and paying for functionality again. – Joel