Skip to content
fogus edited this page Jul 16, 2011 · 31 revisions

Motivations for using Google's Closure Tools

Clojure is nothing if not practical. One of the core design principles of the language has always been that of a symbiotic relationship with the host platform. ClojureScript is no different. That is, it leverages the full capabilities of the Google Closure libraries and Closure compiler in much the same way that Clojure on the JVM leverages Java libraries and the JIT.

Libraries

A ClojureScript implementation philosophy is one built around the rock-solid Google Closure libraries. That is, ClojureScript is written in Clojure and ClojureScript interoperating with the Google Clojure javascript libraries. One should be mindful that the semantics of ClojureScript are mostly those of Clojure, but at the interop level they are Google Closure. For now, ClojureScript development is focused on making the interoperability between ClosureScript and Google Closure rock-solid and all immediate offers will likely be built on top of the latter. That is not to say that libraries leveraging interop between ClojureScript and other JavaScript libraries (e.g. JQuery) is discouraged, only that Google Closure will remain the primary interoperability platform for the core libraries.

Minification

Google's Closure Tools also provide a minification compiler available to the ClojureScript compiler via command-line flags. As a summary, the minification compiler takes the generated JavaScript produced by the ClojureScript compiler and renames variables to shorter names, removes whitespace, removes comments, etc. in an effort to reduce the JavaScript source size while maintaining the program semantics. While useful, rote minification of this sort does not scale. That is, while it certainly reduces gross size, the size of the total source will always increase as more source code is added.

Dead code analysis

Google's Closure compiler provides an advanced setting allowing a more more aggressive minification strategy than that outlined above. In fact, the Google Closure compiler uses highly sophisticated techniques for identifying and eliminating dead code (i.e. code that is never called nor reachable). The downside of this fact is that the style of the JavaScript code must conform to a certain standard in order to achieve maximum minification. Therefore, it has been the goal of the ClojureScript core developers to ensure that the generated JavaScript code is maximally minifiable.

Learn More

Google Closure book

The primary reference for the Google Closure tools is the Google Closure book by O'Reilly Closure: The Definitive Guide written by Michael Bolin. This book is highly recommended for anyone hoping to leverage the full power of ClojureScript interoperability, ClojureScript contributors, and those simply curious about advanced JavaScript techniques and tools.

Clone this wiki locally