Automagically minimize javascript in Eclipse on Windows

The WordPress tool I’m developing uses jQuery scripting. I’ve seen people including a minimized version of the scripting and I think that’s a good approach. I’m using Eclipse on Windows on my development system and it happened more than once that I forgot to include the minimized version of the scripting. I found a solution in my search for a way to do this automatically.

The basics are in this post by Nicolas DEBARNOT. I created a build which uses the Microsoft Ajax Minifier. The builder I’m using has some small changes to the original one, to make sure the builder processes javascript that should be minimized. These files are named <name>.dev.js, the minimized output is written to <name>.js.
Here’s the content of the batch file I’m using. You’re free to use it at your own risk. Be careful though as it may damage your scripting. Replace the dots by the name of the Ajax Minifier installation directory.

@echo off
set inputfile=%1
if not %inputfile% == %outputfile% (
  "...Microsoft\Microsoft Ajax Minifier 4\AjaxMin.exe" -clobber:true %inputfile% -o %outputfile%

It’s not entirely full-proof. Eclipse will complain about the resource being out of sync and needing refresh. I’ll update this post when I find a way around that.

Update: There’s an easy way around eclipse complaining about the resource needing a refresh. Check “Refresh resources upon completion” from the “Refresh” tab, and select “The folder containing the selected resource”. Don’t forget to save the settings.

One thought on “Automagically minimize javascript in Eclipse on Windows”

Leave a Reply

Your email address will not be published. Required fields are marked *