Closure Compiler For javascript

The folks over at Google have hit another winner.If you have'nt been introduced to Google's Closure Compiler you missing out on a great tool.To put it in Google's own words:

"The Closure Compiler is a tool for making JavaScript download and run faster. It is a true compiler for JavaScript. Instead of compiling from a source language to machine code, it compiles from JavaScript to better JavaScript. It parses your JavaScript, analyzes it, removes dead code and rewrites and minimizes what's left. It also checks syntax, variable references, and types, and warns about common JavaScript pitfalls"

It has a good API so you can tweak quite a bit of the program output. I would recommend, if you have several scripts or programs to compile, to use a good batch command and just input the JS file names as the variable's each time. I have noticed it needs the files in the order they would normally load. If you don't do this you may run into sets and calls in the output file that can't be reached. Much like loading a JS call in your header before the JS function is loaded. Also, there is a limit to the number of files it can compile together. The command line version has no limit as far as size of file. If you have several JS files there is a python library add on  companion to help with loading the files in the correct order.

The program will also do code checking but, as with any testing program, you should only use the warnings or errors as guidelines to troubleshoot. I had some warnings in one program but they all pointed to some code the compiler didn't grasp. It still compiled and ran normally after the compilation. You should still check any warnings and especially errors to see if it isn't something you could tweak or fix.

 There is also a web UI so go over to https://developers.google.com/closure/compiler/ and check out their Javascript Compiler. One last and very important comment is to keep your original JS files. If you every have to change or add any code you will need them!

by Jim Atkins "thedosmann"

Memphis Web Programming