# Google Closure Tools

> Mediated Wiki article. Canonical URL: https://mediated.wiki/source/Google_Closure_Tools
> Markdown URL: https://mediated.wiki/source/Google_Closure_Tools.md
> Source: https://en.wikipedia.org/wiki/Google_Closure_Tools
> Source revision: 1331405174
> License: Creative Commons Attribution-ShareAlike 4.0 International (https://creativecommons.org/licenses/by-sa/4.0/)

{{short description|JavaScript developer toolkit}}
{{Promotional|date=October 2019}}
{{Infobox software
| name = Google Closure Tools
| logo = Closure logo.svg
| logo upright = yes
| screenshot = 
| caption = 
| author = [Google](/source/Google)
| developer = 
| released = November 5, 2009<ref>{{cite web |url=http://googlecode.blogspot.com/2009/11/introducing-closure-tools.html |title=Introducing Closure Tools - The official Google Code blog |date=5 November 2009}}</ref>
| discontinued = yes
| latest release version = {{wikidata|property|reference|edit| Q79554 |P348}}
| latest release date = {{start date and age|{{wikidata|qualifier| Q79554 |P348|P577}}}}
| programming language = [Java](/source/Java_(programming_language))
| operating system = 
| platform = 
| language = [JavaScript](/source/JavaScript)
| genre = [Ajax framework](/source/Ajax_framework)
| license = [Apache License 2.0](/source/Apache_License_2.0)
| website = {{Official URL}}
}}

'''Google Closure Tools'''<ref>Bolin, Michael, "Closure: The Definitive Guide", O'Reilly Media Inc., Sebastopol, CA, 2010</ref> was a set of tools built with the goal of helping [developers](/source/Web_developer) optimize rich [web application](/source/web_application)s with [JavaScript](/source/JavaScript). It was developed by [Google](/source/Google) for use in their [web application](/source/web_application)s such as [Gmail](/source/Gmail), [Google Docs](/source/Google_Docs) and [Google Maps](/source/Google_Maps).<ref>{{cite web |url=https://developers.google.com/closure/faq |title=FAQ - Closure Tools|website=Google Developers}}</ref> As of August 1, 2024 the Closure Library has been sunset, for not "meeting the needs of modern JavaScript development".<ref>{{cite web |url=https://github.com/google/closure-library/issues/1214 |title=Closure Library is in Maintenance Mode}}</ref>

==Closure Compiler==
The Closure Compiler is a tool that attempts to compress and optimize JavaScript code, at the expense of [human readability](/source/human-readable_code). Unlike an actual [compiler](/source/compiler), it does not compile from JavaScript to [machine code](/source/machine_code) but rather minifies JavaScript.

The process executes the following steps:

# Parses the submitted JavaScript
# Analyzes the JavaScript 
# [Removes any dead code](/source/dead_code_removal)
# Rewrites and [minifies](/source/minification_(programming)) what is left

It also checks [syntax](/source/Syntax_(programming_languages)), [variable](/source/Variable_(computer_science)) [references](/source/Reference_(computer_science)), and [types](/source/data_type) and warns about [common JavaScript pitfalls](/source/antipattern).

It supports [transpiling](/source/Source-to-source_compiler) modern [ECMAScript](/source/ECMAScript) code to ECMAScript 5 to achieve a wider range of [browser](/source/web_browser) compatibility, similar to [Babel](/source/Babel_(transcompiler)). This obviated Traceur Compiler, another project that supported transpiling ES6 to ES3.<ref>{{Cite web|url=https://github.com/google/traceur-compiler|title= Traceur is a JavaScript.next-to-JavaScript-of-today compiler|website=[GitHub](/source/GitHub)}}</ref>

The Closure compiler also supports [type checking](/source/type_checking) via [JSDoc](/source/JSDoc) type annotations.<ref>{{cite web |url=https://github.com/google/closure-compiler/wiki/Annotating-JavaScript-for-the-Closure-Compiler |title=Annotating JavaScript for the Closure Compiler |website=[GitHub](/source/GitHub) }}</ref>

=== CLI ===
The Closure Compiler is available for use through [command line](/source/Command-line_interface) tools:

* [Java](/source/Java_(software_platform))-based application run from the shell which compiles a list of specified JavaScript files
* [npm](/source/npm_(software)) package <code>google-closure-compiler</code> which provides three compilers: native binary executable (via [GraalVM](/source/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.<ref>{{cite web |url=https://closure-compiler.appspot.com/home |title=Closure Compiler Service}}</ref>

'''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.<ref>{{cite web |url=https://developers.google.com/closure/compiler/docs/api-ref |title=Closure Compiler Service API Reference |access-date=2023-07-18}}</ref>

=== Ecosystem ===
Programming languages that transpile to JavaScript can use the Closure Compiler in their toolchain. For example, the Closure Compiler is used in [ClojureScript](/source/ClojureScript) to optimize the compiled JavaScript.<ref>{{cite web |title=Motivations for using Google's Closure Tools |website=[GitHub](/source/GitHub) |url=https://github.com/clojure/clojurescript/wiki/Google%20Closure}}</ref>

=== Internals ===
Closure Compiler is built upon a modified version of the [Rhino](/source/Rhino_(JavaScript_engine)) JS engine built by Mozilla, [Google Guava](/source/Google_Guava), a Java standard library, [Protocol Buffers](/source/Protocol_Buffers), Gson and various other tools for testing. It also ships with built-in JavaScript [JSDoc](/source/JSDoc) annotations for various popular projects like Node.js' standard API library, JQuery, and Google Map APIs.

==Closure Library==
The Closure Library is a [JavaScript library](/source/JavaScript_library), written specifically to take advantage of the Closure Compiler, based on a [modular architecture](/source/modular_programming). It provides [cross-browser](/source/cross-browser) functions for [DOM](/source/document_object_model) manipulations and [events](/source/event_(computing)), [Ajax](/source/Ajax_(programming)) and [JSON](/source/JSON), as well as more high-level objects such as [User Interface](/source/User_Interface) widgets and Controls.

==Closure Templates==
Closure Templates are a [templating system](/source/template_processor) for dynamically generating [HTML](/source/HTML) in both [Java](/source/Java_(programming_language))<ref>{{cite web |url=https://github.com/google/closure-templates/blob/master/documentation/codelabs/helloworlds/helloworld_java.md |title=Hello World Using Java |website=github.com}}</ref> and [JavaScript](/source/JavaScript).<ref>{{cite web |url=https://github.com/google/closure-templates/blob/master/documentation/codelabs/helloworlds/helloworld_js.md |title=Hello World Using JavaScript |website=github.com}}</ref>

Since the language is apparently referred to as "Soy" internally by Google, and "Soy" remains in some of the documentation and classes,<ref>{{cite web |url=https://code.google.com/archive/p/closure-templates/source |title=Google Code Archive - Long-term storage for Google Code Project Hosting. |website=code.google.com}}</ref> sometimes Closure Templates are referred to as "Soy Templates".

== Closure Stylesheets ==
Closure Stylesheets provide extensions to [CSS](/source/Cascading_Style_Sheets), which are transpiled 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](/source/Sass_(style_sheet_language)) and [PostCSS](/source/PostCSS).<ref>{{cite web |url=https://github.com/google/closure-stylesheets/pull/151/files |title=Officially mark this repository as end-of-life |author=Weizenbaum, Natalie |date=2021-11-01 |access-date=2023-07-18}}</ref>

==See also==
{{Portal|Free and open-source software}}
* [Google Web Toolkit](/source/Google_Web_Toolkit)
* [JSDoc](/source/JSDoc)
* [TypeScript](/source/TypeScript)
* [Minification (programming)](/source/Minification_(programming))
* [Source-to-source compiler](/source/Source-to-source_compiler)

==References==
{{Reflist}}

==External links==
*{{Official website}}
*[https://github.com/flynetworks/typo3-flow-google-closure Package for TYPO3 Flow]

{{Google FOSS}}
{{JavaScript}}

Category:2009 software
Category:Free software programmed in Java
Category:JavaScript libraries
Category:Web development software
Closure Tools
Category:Software using the Apache license

---
Adapted from the Wikipedia article [Google Closure Tools](https://en.wikipedia.org/wiki/Google_Closure_Tools) by Wikipedia contributors ([contributor history](https://en.wikipedia.org/wiki/Google_Closure_Tools?action=history)). Available under [Creative Commons Attribution-ShareAlike 4.0 International](https://creativecommons.org/licenses/by-sa/4.0/). Changes may have been made.
