Google Closure Library
   HOME

TheInfoList



OR:

Google Closure Tools was a set of tools built with the goal of helping developers optimize rich
web application A web application (or web app) is application software that is created with web technologies and runs via a web browser. Web applications emerged during the late 1990s and allowed for the server to dynamically build a response to the request, ...
s with
JavaScript JavaScript (), often abbreviated as JS, is a programming language and core technology of the World Wide Web, alongside HTML and CSS. Ninety-nine percent of websites use JavaScript on the client side for webpage behavior. Web browsers have ...
. It was developed by
Google Google LLC (, ) is an American multinational corporation and technology company focusing on online advertising, search engine technology, cloud computing, computer software, quantum computing, e-commerce, consumer electronics, and artificial ...
for use in their
web application A web application (or web app) is application software that is created with web technologies and runs via a web browser. Web applications emerged during the late 1990s and allowed for the server to dynamically build a response to the request, ...
s such as
Gmail Gmail is the email service provided by Google. it had 1.5 billion active user (computing), users worldwide, making it the largest email service in the world. It also provides a webmail interface, accessible through a web browser, and is also ...
, Google Docs and
Google Maps Google Maps is a web mapping platform and consumer application offered by Google. It offers satellite imagery, aerial photography, street maps, 360° interactive panorama, interactive panoramic views of streets (Google Street View, Street View ...
. As of Aug 1, 2024 the Closure Library has been sunset, for not "meeting the needs of modern JavaScript development".


Closure Compiler

The Closure Compiler is a tool that attempts to compress and optimize JavaScript code, at the expense of human readability. Unlike an actual
compiler In computing, a compiler is a computer program that Translator (computing), translates computer code written in one programming language (the ''source'' language) into another language (the ''target'' language). The name "compiler" is primaril ...
, it does not compile from JavaScript to
machine code In computer programming, machine code is computer code consisting of machine language instructions, which are used to control a computer's central processing unit (CPU). For conventional binary computers, machine code is the binaryOn nonb ...
but rather minifies JavaScript. The process executes the following steps: # Parses the submitted JavaScript # Analyzes the JavaScript # Removes any dead code # Rewrites and minifies what is left It also checks
syntax In linguistics, syntax ( ) is the study of how words and morphemes combine to form larger units such as phrases and sentences. Central concerns of syntax include word order, grammatical relations, hierarchical sentence structure (constituenc ...
, variable
references A reference is a relationship between Object (philosophy), objects in which one object designates, or acts as a means by which to connect to or link to, another object. The first object in this relation is said to ''refer to'' the second object. ...
, and
types Type may refer to: Science and technology Computing * Typing, producing text via a keyboard, typewriter, etc. * Data type, collection of values used for computations. * File type * TYPE (DOS command), a command to display contents of a file. * Ty ...
and warns about common JavaScript pitfalls. It supports transpiling modern
ECMAScript ECMAScript (; ES) is a standard for scripting languages, including JavaScript, JScript, and ActionScript. It is best known as a JavaScript standard intended to ensure the interoperability of web pages across different web browsers. It is stan ...
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. The Closure compiler also supports
type checking In computer programming, a type system is a logical system comprising a set of rules that assigns a property called a ''type'' (for example, integer, floating point, string) to every '' term'' (a word, phrase, or other set of symbols). Usu ...
via JSDoc type annotations.


CLI

The Closure Compiler is available for use through command line tools: *
Java Java is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea (a part of Pacific Ocean) to the north. With a population of 156.9 million people (including Madura) in mid 2024, proje ...
-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. 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.


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.


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.


Closure Library

The Closure Library is a JavaScript library, written specifically to take advantage of the Closure Compiler, based on a modular architecture. It provides cross-browser functions for DOM manipulations and events,
Ajax Ajax may refer to: Greek mythology and tragedy * Ajax the Great, a Greek mythological hero, son of King Telamon and Periboea * Ajax the Lesser, a Greek mythological hero, son of Oileus, the king of Locris * Ajax (play), ''Ajax'' (play), by the an ...
and
JSON JSON (JavaScript Object Notation, pronounced or ) is an open standard file format and electronic data interchange, data interchange format that uses Human-readable medium and data, human-readable text to store and transmit data objects consi ...
, as well as more high-level objects such as
User Interface In the industrial design field of human–computer interaction, a user interface (UI) is the space where interactions between humans and machines occur. The goal of this interaction is to allow effective operation and control of the machine fro ...
widgets and Controls.


Closure Templates

Closure Templates are a templating system for dynamically generating
HTML Hypertext Markup Language (HTML) is the standard markup language for documents designed to be displayed in a web browser. It defines the content and structure of web content. It is often assisted by technologies such as Cascading Style Sheets ( ...
in both
Java Java is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea (a part of Pacific Ocean) to the north. With a population of 156.9 million people (including Madura) in mid 2024, proje ...
and
JavaScript JavaScript (), often abbreviated as JS, is a programming language and core technology of the World Wide Web, alongside HTML and CSS. Ninety-nine percent of websites use JavaScript on the client side for webpage behavior. Web browsers have ...
. Since the language is apparently referred to as "Soy" internally by Google, and "Soy" remains in some of the documentation and classes, sometimes Closure Templates are referred to as "Soy Templates".


Closure Stylesheets

Closure Stylesheets provide extensions to CSS, 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 and PostCSS.


See also

* Google Web Toolkit * JSDoc *
TypeScript TypeScript (abbreviated as TS) is a high-level programming language that adds static typing with optional type annotations to JavaScript. It is designed for developing large applications and transpiles to JavaScript. It is developed by Micr ...
* Minification (programming) *
Source-to-source compiler A source-to-source translator, source-to-source compiler (S2S compiler), transcompiler, or transpiler is a type of translator that takes the source code of a program written in a programming language as its input and produces an equivalent so ...


References


External links

*
Package for TYPO3 Flow
{{JavaScript 2009 software Free software programmed in Java (programming language) JavaScript libraries Web development software Closure Tools