Category Archives: Closure

Removing Debug Statements from Javascript via compiler

We all know the pain of getting a bug filed against some of your code and having to dig through it later to find the root cause. Especially, since many times we end up having to add back in all of our debug statements in order to track down the issue. There has to be a better way. What if we could write all of our JavaScript with the debug code left in?

The Better way

By now, we are all using some compiler to compile your code. Right? If you haven’t started, grab the Closure Compiler to follow through on this example.

  1. Download the latest Closure Compiler
  2. Unzip
  3. Copy the compiler.jar file into your directory with the JS Files.
  4. follow along below and enjoy!

If you are using Closure Compiler or Uglify already, you are in luck! Both of these compilers allow you to annotate your JavaScript. Annotating your files allows you to describe them to the compiler. Things like @license will make sure that the comment goes to the top of the file after compression. Look through the list to see what each one does. We are going to focus on @define.

Continue reading