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;8 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 a 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 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 build upon modified version of Rhino JS engine build by Mozilla, Google Guava, a Java standard library, Protocol Buffers, Gson and various others tools for testing. It also ships with built-in JavaScript JSDoc annotations for various popular projects like Node.js's standard API library, JQuery, Google Map APIs etc..

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]

Because the language was 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 provided 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 has been deprecated in favor of tools such as Sass and PostCSS. [13]

See also

Related Research Articles

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.

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.

Svelte is a free and open-source component-based front-end software framework, and language created by Rich Harris and maintained by the Svelte core team members.

A single-page application (SPA) is a web application or website that interacts with the user by dynamically rewriting the current web page with new data from the web server, instead of the default method of a web browser loading entire new pages. The goal is faster transitions that make the website feel more like a native app.

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.

Content Security Policy (CSP) is a computer security standard introduced to prevent cross-site scripting (XSS), clickjacking and other code injection attacks resulting from execution of malicious content in the trusted web page context. It is a Candidate Recommendation of the W3C working group on Web Application Security, widely supported by modern web browsers. CSP provides a standard method for website owners to declare approved origins of content that browsers should be allowed to load on that website—covered types are JavaScript, CSS, HTML frames, web workers, fonts, images, embeddable objects such as Java applets, ActiveX, audio and video files, and other HTML5 features.

In software development, a polyfill is code that implements a feature of the development 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>

Ember.js is an open-source JavaScript web framework that utilizes a component-service pattern. It is designed with the aim of allowing 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. It provides additional programming languages and execution modes. The first production-ready release, GraalVM 19.0, was distributed in May 2019. The most recent release is GraalVM for JDK 22, made available in March 2024.

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 popular approach to build microfrontends.

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 library 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.

<span class="mw-page-title-main">AssemblyScript</span> Programming language, variant of TypeScript that compiles to WebAssembly

AssemblyScript is a TypeScript-based programming language that is optimized for, and statically compiled to, WebAssembly. Resembling ECMAScript and JavaScript, but with static types, the language is developed by the AssemblyScript Project with contributions from the AssemblyScript community.

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.