Google Closure Tools

Last updated
Google Closure Tools
Original author(s) Google
Initial releaseNovember 5, 2009 [1]
Stable release
v20230802 [2]   OOjs UI icon edit-ltr-progressive.svg / 2 August 2023;13 months ago (2 August 2023)
Repository
Written in Java
Available in JavaScript
Type Ajax framework
License Apache License 2.0
Website developers.google.com/closure/

Google Closure Tools [3] is a set of tools to help developers build rich web applications with JavaScript. It was developed by Google for use in their web applications such as Gmail, Google Docs and Google Maps. [4] As of 2023, the project had over 230K LOCs not counting the embedded Mozilla Rhino compiler.

Contents

Closure Compiler

The Closure Compiler is a tool for making JavaScript downloads run faster, at the expense of human readability. It does not compile from JavaScript to machine code but rather compiles from JavaScript to more efficient JavaScript.

The process executes the following steps:

  1. Parses the submitted JavaScript
  2. Analyzes the JavaScript
  3. Removes any dead code
  4. Rewrites and minifies what is left

It also checks syntax, variable references, and types and warns about common JavaScript pitfalls.

It supports transpiling modern ECMAScript code to ECMAScript 5 so that programmers can write JavaScript that uses new ECMAScript features, and run it in browsers or other environments that do not yet support them. This obviated Traceur Compiler, another project that supported transpiling ES6 to ES3. [5]

The Closure compiler also supports type checking via type annotations that must be written in JSDoc comments. [6]

CLI

Google provides command line tools used to optimize and compile .js files:

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 with the optimized JavaScript on the right side for the user to copy. [7]

An API is available, accessible via POST requests, parameters include:

The service is marked as deprecated and will eventually be removed. [8]

Ecosystem

Programming languages that transpile to JavaScript benefit from Closure Tools. For example, Closure Compiler helps to make ClojureScript practical by making the compiled JavaScript code more efficient. [9]

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 and JSON, as well as more high-level objects such as User Interface widgets and Controls.

Closure Templates

Closure Templates are a templating system for dynamically generating HTML in both Java [10] and JavaScript. [11]

Since the language apparently referred to as "Soy" internal to Google, and "Soy" remains in some of the documentation and classes, [12] 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. [13]

See also

Related Research Articles

<span class="mw-page-title-main">JavaScript</span> High-level programming language

JavaScript, often abbreviated as JS, is a programming language and core technology of the Web, alongside HTML and CSS. 99% of websites use JavaScript on the client side for webpage behavior.

ECMAScript 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 standardized by Ecma International in the document ECMA-262.

Minification is the process of removing all unnecessary characters from the source code of interpreted programming languages or markup languages without changing its functionality. These unnecessary characters usually include white space characters, new line characters, comments, and sometimes block delimiters, which are used to add readability to the code but are not required for it to execute. Minification reduces the size of the source code, making its transmission over a network more efficient. In programmer culture, aiming at extremely minified source code is the purpose of recreational code golf competitions.

TypeScript is a free and open-source high-level programming language developed by Microsoft that adds static typing with optional type annotations to JavaScript. It is designed for the development of large applications and transpiles to JavaScript. Because TypeScript is a superset of JavaScript, all JavaScript programs are syntactically valid TypeScript, but they can fail to type-check for safety reasons.

JSDoc is a markup language used to annotate JavaScript source code files. Using comments containing JSDoc, programmers can add documentation describing the application programming interface of the code they're creating. This is then processed, by various tools, to produce documentation in accessible formats like HTML and Rich Text Format. The JSDoc specification is released under CC BY-SA 3.0, while its companion documentation generator and parser library is free software under the Apache License 2.0.

V8 is a JavaScript and WebAssembly engine developed by Google for its Chrome browser. V8 is free and open-source software that is part of the Chromium project and also used separately in non-browser contexts, notably the Node.js runtime system.

CommonJS is a project to standardize the module ecosystem for JavaScript outside of web browsers.

A browser speed test is a computer benchmark that scores the performance of a web browser, by measuring the browser's efficiency in completing a predefined list of tasks. In general the testing software is available online, located on a website, where different algorithms are loaded and performed in the browser client. Typical test tasks are rendering and animation, DOM transformations, string operations, mathematical calculations, sorting algorithms, graphic performance tests and memory instructions. Browser speed tests have been used during browser wars to prove superiority of specific web browsers. The popular Acid3 test is no particular speed test but checks browser conformity to web standards.

In software development, a polyfill is code that implements a new standard feature of a deployment environment within an old version of that environment that does not natively support the feature. Most often, it refers to JavaScript code that implements an HTML5 or CSS web standard, either an established standard on older browsers, or a proposed standard on existing browsers. Polyfills are also used in PHP and Python.

asm.js is a subset of JavaScript designed to allow computer software written in languages such as C to be run as web applications while maintaining performance characteristics considerably better than standard JavaScript, which is the typical language used for such applications.

<span class="mw-page-title-main">Ember.js</span> JavaScript framework

Ember.js is an open-source JavaScript web framework that utilizes a component-service pattern. It is designed to allow developers to create scalable single-page web applications by incorporating common idioms, best practices, and patterns from other single-page-app ecosystem patterns into the framework.

<span class="mw-page-title-main">GraalVM</span> Virtual machine software

GraalVM is a Java Development Kit (JDK) written in Java. The open-source distribution of GraalVM is based on OpenJDK, and the enterprise distribution is based on Oracle JDK. As well as just-in-time (JIT) compilation, GraalVM can compile a Java application ahead of time. This allows for faster initialization, greater runtime performance, and decreased resource consumption, but the resulting executable can only run on the platform it was compiled for.

Web Components are a set of features that provide a standard component model for the web allowing for encapsulation and interoperability of individual HTML elements. Web Components are a popular approach when building microfrontends.

<span class="mw-page-title-main">WebAssembly</span> Cross-platform assembly language and bytecode designed for execution in web browsers

WebAssembly (Wasm) defines a portable binary-code format and a corresponding text format for executable programs as well as software interfaces for facilitating communication between such programs and their host environment.

NativeScript provides platform APIs directly to the JavaScript runtime for a rich TypeScript development experience. As an open-source framework to develop apps for iOS, visionOS and Android platforms combining a best of all worlds approach marrying familiar Web approaches like CSS and view templating with common platform languages it delivers a liberating toolset for developers. It was originally conceived and developed by Bulgarian company Telerik, later acquired by Progress Software. At the end of 2019 responsibility for the NativeScript project was taken over by long-time Progress partner, nStudio. In December 2020, nStudio also oversaw the induction of NativeScript into OpenJS Foundation as an Incubating Project. NativeScript apps are built using JavaScript, or by using any programming language that transpiles to JavaScript, such as TypeScript. NativeScript supports the Angular and Vue JavaScript frameworks. Mobile applications built with NativeScript result in fully native apps, which use the same APIs as if they were developed in Xcode or Android Studio. Additionally, software developers can re-purpose third-party libraries from CocoaPods, Maven, and npm.js in their mobile applications without the need for wrappers.

JerryScript is an ultra-lightweight JavaScript engine for the Internet of things. It is capable of executing ECMAScript 5.1 source code on devices with less than 64 KB of memory.

<span class="mw-page-title-main">Vue.js</span> Open-source JavaScript library for building user interfaces

Vue.js is an open-source model–view–viewmodel front end JavaScript framework for building user interfaces and single-page applications. It was created by Evan You and is maintained by him and the rest of the active core team members.

This is a list of articles related to the JavaScript programming language.

<span class="mw-page-title-main">Deno (software)</span> Secure JavaScript and TypeScript runtime

Deno is a runtime for JavaScript, TypeScript, and WebAssembly that is based on the V8 JavaScript engine and the Rust programming language. Deno was co-created by Ryan Dahl, who also created Node.js.

References

  1. "Introducing Closure Tools - The official Google Code blog". 5 November 2009.
  2. "v20230802: RemoveUnusedCode: log reasons for not removing variables". 2 August 2023. Retrieved 4 August 2023.
  3. Bolin, Michael, "Closure: The Definitive Guide", O'Reilly Media Inc., Sebastopol, CA, 2010
  4. "FAQ - Closure Tools". Google Developers.
  5. "Traceur is a JavaScript.next-to-JavaScript-of-today compiler". GitHub .
  6. "Annotating JavaScript for the Closure Compiler". GitHub .
  7. "Closure Compiler Service".
  8. "Closure Compiler Service API Reference" . Retrieved 2023-07-18.
  9. "Motivations for using Google's Closure Tools". GitHub .
  10. "Hello World Using Java". github.com.
  11. "Hello World Using JavaScript". github.com.
  12. "Google Code Archive - Long-term storage for Google Code Project Hosting". code.google.com.
  13. Weizenbaum, Natalie (2021-11-01). "Officially mark this repository as end-of-life" . Retrieved 2023-07-18.