-
Notifications
You must be signed in to change notification settings - Fork 788
Google Closure
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.
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).
ClosureScript also encapsulates Google Closure's dependency management system offering three primitives addDependency
, provide
, and require
that enable compile-time dependency inclusions. This capability is leveraged to allow fine-grained imports and exports of ClosureScript namespaces and functions and also external JavaScript libraries for interoperability purposes.
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.
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 strict standard in order to achieve maximum minification potential. Therefore, it has been the goal of the ClojureScript core developers to ensure that the generated JavaScript code is maximally minifiable through an observance to said idioms and through the use of the Closure libraries and dependency system.
The primary reference for the Google Closure tools is O'Reilly's 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.
- Rationale
- Quick Start
- Differences from Clojure
- [Usage of Google Closure](Google Closure)