The Closure Compiler is a tool that attempts to compress and optimize JavaScript code, at the expense of human readability. Unlike an actual compiler, it does not compile from JavaScript to machine code but rather minifies JavaScript.
It supports transpiling modern ECMAScript code to ECMAScript 5 to achieve a wider range of browser compatibility, similar to Babel. This obviated Traceur Compiler, another project that supported transpiling ES6 to ES3.[6]
The Closure Compiler is available for use through command line tools:
Java-based application run from the shell which compiles a list of specified JavaScript files
npm package google-closure-compiler which provides three compilers: native binary executable (via GraalVM), Java and a JavaScript-based one
Closure Compiler Service
The Closure Compiler Service application provides a form for a user to input a URL pointing to a JavaScript source or enter JavaScript source code in a text box. The website will display the compiled JavaScript on the right side for the user to copy.[8]
An API is available, accessible via POST requests, parameters include:
The JavaScript to be optimized, or a URL pointing to it
Optimization level
Emit errors and warnings
Output format i.e. JSON, XML, or text
The service is marked as deprecated and will eventually be removed.[9]
Ecosystem
Programming languages that transpile to JavaScript can use the Closure Compiler in their toolchain. For example, the Closure Compiler is used in ClojureScript to optimize the compiled JavaScript.[10]
Internals
Closure Compiler is built upon a modified version of the Rhino JS engine built by Mozilla, Google Guava, a Java standard library, Protocol Buffers, Gson and various other tools for testing. It also ships with built-in JavaScript JSDoc annotations for various popular projects like Node.js' standard API library, JQuery, and Google Map APIs.
Since the language is apparently referred to as "Soy" internally by Google, and "Soy" remains in some of the documentation and classes,[13] sometimes Closure Templates are referred to as "Soy Templates".
Closure Stylesheets
Closure Stylesheets provide extensions to CSS, which are transpired to ordinary CSS. Internally in Google, this extended version of CSS is referred to as GSS.
As of November 2021, Closure Stylesheets have been deprecated in favor of tools such as Sass and PostCSS.[14]