Friday 3 June 2011

Minify JavaScript in Eclipse with Google Closure Compiler

Recently I decided it was time to start minifying my jQuery scripts before deploying them to decrease download time. After lots of research, I found Google Closure Compiler, which not only minifies, it also obfuscates and even optimises your scripts (dead code removal etc)! The best place to get this done is within Eclipse, and you can do it using a plugin by Rock Star Apps. Details here: http://update.rockstarapps.com/index.html.

Basically, add this URL to your Eclipse Software Sites: http://update.rockstarapps.com, and install Rockstar Web Optimizer. You should then be able to right click a Javascript file and go Rockstarapps > Compress and you get loads of options like Google Closure Compiler, YUI Compressor etc.

You can even tell it to auto-build. When you are on the options screen, select "Automatically recreate file when one of it's dependencies changes", and then it will rebuild every time you save the source file.

UPDATE: sadly it appears rockstarapps are no more. If anyone knows of another way to achieve this, I would be very grateful!

3 comments:

  1. I know in this case you don't use Visual Studio, but in case anyone here
    besides me uses Visual Studio and does need JS minification (and
    concatenation) a good solution is Chirpy.

    ReplyDelete
  2. This guy wrote something similar:
    http://www.normalesup.org/~simonet/soft/ow/eclipse-closure-javascript.en.html

    ReplyDelete
  3. Rock Star Apps can't be found anymore because of the hijacked domain, but you can still manually download and install it. I just did and it worked: http://blog.avirtualhome.com/rockstarapps-for-eclipse

    ReplyDelete