Google Closure Tools
| Company type | Software suite |
|---|---|
| Industry | Software development |
| Founded | 2009 |
| Founder | |
| Fate | Closure Library discontinued on August 1, 2024 |
| Products | Closure Compiler, Closure Library, Closure Templates, Closure Stylesheets |
| Owner | |
| Website | https://developers.google.com/closure/ |
Google Closure Tools comprised a collection of utilities created to assist developers in enhancing the efficiency of complex web applications utilizing JavaScript. Originally developed by Google for its internal platforms such as Gmail, Google Docs, and Google Maps, the suite focused on boosting both performance and code maintainability. However, the Closure Library was officially discontinued on August 1, 2024, as it no longer aligned with contemporary JavaScript development standards.
Closure Compiler
The Closure Compiler functions by parsing and analyzing JavaScript code to eliminate unused segments and compress the remainder, prioritizing optimization rather than preserving code readability.
It performs syntax validation, checks variable references, and analyzes data types, issuing alerts for typical JavaScript errors. The compiler also enables transpilation from modern ECMAScript versions down to ECMAScript 5, facilitating compatibility across a wider range of browsers. This capability positions it similarly to Babel and has superseded earlier solutions like Traceur Compiler.
Moreover, Closure Compiler incorporates type checking through JSDoc annotations, which contributes to improved code robustness and easier maintenance.
CLI
The Closure Compiler can be utilized through various command line options:
- A shell application built on Java that compiles designated JavaScript files
- An npm package named
google-closure-compileroffering three variants: native binary (leveraging GraalVM), Java-based, and JavaScript-based compilers
Closure Compiler Service
This service provides a web interface where users can submit either a URL or raw JavaScript source code and receive the optimized output ready for copying.
An API allows POST requests with parameters such as:
- JavaScript source or URL to be processed
- Desired optimization level
- Configuration for error and warning reporting
- Selection of output format (JSON, XML, or plain text)
Note that this service is deprecated and slated for removal.
Ecosystem
Several languages that compile into JavaScript incorporate the Closure Compiler as part of their build process; for example, ClojureScript utilizes it to refine generated code.
Internals
The compiler is constructed atop a customized version of Mozilla’s Rhino engine and depends on libraries including Google Guava, Protocol Buffers, Gson, along with testing frameworks. It also comes equipped with built-in JavaScript JSDoc annotations covering major projects like Node.js APIs, JQuery, and Google Maps.
Closure Library
Designed as a modular JavaScript library, the Closure Library works in tandem with the Closure Compiler. It provides cross-browser tools for manipulating the DOM, handling events, managing Ajax requests, processing JSON data, and includes sophisticated user interface widgets and controls.
Closure Templates
Closure Templates serve as a templating framework for producing dynamic HTML content in both Java and JavaScript. Internally referred to as "Soy," this designation remains present in some documentation and class names, resulting in the alternative label "Soy Templates."
Closure Stylesheets
Closure Stylesheets offer an extended syntax over standard CSS, which is then transpiled into conventional CSS. Within Google, this enhanced CSS variant is known as GSS.
As of November 2021, Closure Stylesheets have been deprecated in favor of newer technologies such as Sass and PostCSS.