Minification (programming)

Short description: Removal of unnecessary characters in code without changing its functionality

Minification (also minimisation or minimization) 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 (e.g. the Internet) more efficient. In programmer culture, aiming at extremely minified source code is the purpose of recreational code golf competitions.

Minification can be distinguished from the more general concept of data compression in that the minified source can be interpreted immediately without the need for an uncompression step: the same interpreter can work with both the original as well as with the minified source.

The goals of minification are not the same as the goals of obfuscation; the former is often intended to be reversed using a pretty-printer[citation needed] or unminifier. However, to achieve its goals, minification sometimes uses techniques also used by obfuscation; for example, shortening variable names and refactoring the source code. When minification uses such techniques, the pretty-printer or unminifier can only fully reverse the minification process if it is supplied details of the transformations done by such techniques. If not supplied those details, the reversed source code will contain different variable names and control flow, even though it will have the same functionality as the original source code.

## Contents

* 1 Example
* 2 History
* 3 Source mapping
* 4 Types
* 4.1 Tools
* 4.2 Web development
* 5 References

## Example

For example, the JavaScript code

// This is a comment that will be removed by the minifier
var array = [];
for (var i = 0; i < 20; i++) {
array[i] = i;

is equivalent to but longer than

for(var a=[],i=0;i<20;a[i]=i++);

## History

In 2001 Douglas Crockford introduced JSMin,[1] which removed comments and whitespace from JavaScript code.[2] It was followed by YUI Compressor in 2007.[2] In 2009, Google opened up its Closure toolkit, including Closure Compiler which contained a source mapping feature together with a Firefox extension called Closure Inspector.[3] In 2010, Mihai Bazon introduced UglifyJS, which was superseded by UglifyJS2 in 2012; the rewrite was to allow for source map support.[4] From 2017, Alex Lam took over maintenance and development of UglifyJS2, replacing it with UglifyJS3 which unified the CLI with the API.[5] In 2018, Terser has been forked from uglify-es[6][7] and has gained momentum since; in 2020 it outstripped UglifyJS when measured in daily downloads.[8]

## Source mapping

A Source Map is a file format that allows software tools for JavaScript to display different code to a user than the code actually executed by the computer. For example, to aid in debugging of minified code, by "mapping" this code to the original unminified source code instead.

The original format was created by Joseph Schorr as part of the Closure Inspector minification project.[9] Version 2 and 3 of the format reduced the size of the map files considerably.[9]

## Types

### Tools

Visual Studio Code comes with minification support for several languages. It can readily browse the Visual Studio Marketplace to download and install additional minifiers.

JavaScript optimizers can minify and generate source maps. In addition certain online tools can compress CSS files.[citation needed]

### Web development

Components and libraries for Web applications and websites have been developed to optimize file requests and reduce page load times by shrinking the size of various files.

JavaScript and Cascading Style Sheet (CSS) resources may be minified, preserving their behavior while considerably reducing their file size. Libraries available online are capable of minification and optimization to varying degrees. Some libraries also merge multiple script files into a single file for client download. JavaScript source maps can make code readable and debuggable even after it has been combined and minified.[10]

## References

1. ↑ Crockford, Douglas (11 September 2001). "JSMin: The JavaScript Minifier". Self-published. https://www.crockford.com/javascript/jsmin.html.
2. ↑ 2.0 2.1 "Code minification". The WebPlatform Project. https://webplatform.github.io/docs/concepts/programming/javascript/minification/.
3. ↑ Paul, Ryan (6 November 2009). "Google opens up its JavaScript development toolbox to all". https://arstechnica.com/information-technology/2009/11/google-opens-up-its-javascript-development-toolbox-to-all/.
4. ↑ Bazon, Mihai (8 November 2012). "Should you switch to UglifyJS2?". Self-published. http://lisperator.net/blog/should-you-switch-to-uglifyjs2/.
5. ↑ "uglify-js NPM". 6 May 2017. https://www.npmjs.com/package/uglify-js/v/3.0.0.
6. ↑ "terser · JavaScript mangler and compressor toolkit for ES6+". https://terser.org/.
7. ↑ https://github.com//terser/commit/3ef6879ecafd12b57e575ec85e6104e71d5a1b6f [bare URL][|permanent dead link|dead link}}]
8. ↑ "Terser vs uglify-js". https://npmtrends.com/terser-vs-uglify-js.
9. ↑ 9.0 9.1 "Source Map Revision 3 Proposal". 2011-01-11. https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit.
10. ↑ Seddon, Ryan (March 21, 2012). "Introduction to JavaScript Source Maps". http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/.

0.00

(0 votes)

Original source: https://en.wikipedia.org/wiki/Minification (programming). Read more

|

Retrieved from "https://handwiki.org/wiki/index.php?title=Minification_(programming)&oldid=232063"