Thursday, July 10, 2014

Pretty beautiful optimized JavaScript


I obviously try to use best practices to make my code as optimized and nicely formatted as possible. But, I use two tools pretty consistently during and after writing a script.

The first thing I do is run it through Google’s Closure Compiler. I use the “SIMPLE_OPTIMIZATIONS” compilation level.

Next, I paste the output from Closure Compiler in to jsbeautifier. They have some great options. I wont get in to how I like my braces. Those conversations can get ugly. :-)

You might ask why I don’t just use the “pretty_print” formatting with Closure Compiler. Well, I like the options with jsbeautifier. It may also just be habit.

I do drop by JSLint on occasion. It is good to get all the feedback I can on my JavaScript code.

There are a zillion IDE, online and local tools to help you optimize, minimize and pretty up your code. I find that these tools are more about learning how to write better JavaScript than any significant performance boost. That is, if you’re starting out with halfway decent code.

Let me know your process. Hopefully it includes peer and up code reviews!

No comments:

Post a Comment