When using the Advanced Optimization option, it forces you to write more concise code, exposing only what really matters to the global namespace.
For now, we’ll only set up a quick way of invoking the Google Closure Compiler from within Visual Studio.
Download the compiler.jar package and unzip it.
Be sure to have at least the java run time installed (the java development kit will of course also do fine), both available here.
In Visual Studio, click “Tools” -> “External Tools”, then click “Add”
Enter the title of your choice, and at the “Command”, click the browse ("…") button and locate java.exe (should be something like this :
At the “Arguments” enter the following:
-jar X:\Path\To\YourDownloadedAndUnzipped\compiler.jar --js $(ItemPath) --js_output_file $(ItemDir)$(ItemFileName).min.js --compilation_level ADVANCED_OPTIMIZATIONS --summary_detail_level 3
Check the “Use Output window” checkbox
Click “Ok” to save your changes
You should see the output folder popup with the following
0 error(s), 0 warning(s)
is broken after the compression.
Making it work with jQuery:
ADVANCED_OPTIMIZATIONS will try to shorten all variables and function names, it breaks any jQuery plugin when compressed.
To overcome this problem, we’ll tell the Google Closure Compiler to use jQuery as an external reference, ensuring that the name of any jQuery function will be preserved.
1. Download the latest uncompressed version of [jQuery](http://jquery.com) ([1.4.2](http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.js) at the time this post was written) to the folder you unzipped "compiler.jar" and call the file `jquery.js` 2. Create a file called `withjQuery.bat` in the same folder and add the following content:
Add another External Tool as before, this time, choose the .bat file you created as “Command”
As “Arguments” enter :
Be sure to check the “Use Output window” checkbox as before
You might want to integrate the Google Closure Compiler as a build step instead of an External Tool as explained here, if so I hope the small tips above will help you do so!
Give it a try!