Skip to content
fogus edited this page Jul 18, 2011 · 27 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 tools, including its libraries, dependency system, and compiler.

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. However, ClosureScript can interoperate with any JavaScript library or framework. The use of the Google Closure libraries in the ClojureScript core is an implementation strategy that allows us to reduce dependencies and ensure compatibility with advanced mode compilation (see below).

Dependency Management

The Google Closure tools also provide a dependency management system built around three primitives addDependency, provide, and require that enables compile-time dependency inclusions. This capability is leveraged to allow a fine-grained imports and exports of ClosureScript namespaces and functions and also external JavaScript libraries for interoperability purposes.

Compiler

Google's Closure Tools also provide a minification compiler available to the ClojureScript compilation process via command-line flags. In summary, the minification compiler receives generated JavaScript produced by the ClojureScript compiler and renames variables to shorter names, removes whitespace, removes comments, etc. in an effort to reduce the 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