Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikipediaThe Free Encyclopedia
Search

Minification (programming)

From Wikipedia, the free encyclopedia
Removal of unnecessary characters in code without changing its functionality
For other uses, seeMinimisation.
"Terser" redirects here. For the basic topic, seeterseness.

Minification (alsominimisation orminimization) is the process of removing all unnecessary characters from thesource code ofinterpreted programming languages ormarkup languages without changing its functionality. These unnecessary characters usually includewhitespace characters,new line characters,comments, and sometimesblock 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 recreationalcode golf competitions and a part of thedemoscene.

Minification can be distinguished from the more general concept ofdata compression in that the minified source can be interpreted immediately without the need for a decompression 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 ofobfuscation; the former is often intended to be reversed using apretty 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.

Example

[edit]

For example, theJavaScript code

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

is equivalent to but longer than

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

History

[edit]

In 2001Douglas Crockford introducedJSMin,[1] which removed comments and whitespace from JavaScript code.[2] It was followed byYUI Compressor in 2007.[2] In 2009, Google opened up its Closure toolkit, includingClosure Compiler which contained a source mapping feature together with a Firefox extension called Closure Inspector.[3] In 2010, Mihai Bazon introducedUglifyJS, 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] Since late 2018, Terser has recommended the bundlerRollupJS [wd].[9]

Source mapping

[edit]

Asource map is afile format that allows software tools forJavaScript to display different code to a user than the code actually executed by the computer. For example, to aid indebugging of minified code, by "mapping" this code to the original unminifiedsource code instead.

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

Types

[edit]

JavaScript andCascading Style Sheets (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.[11]

References

[edit]
  1. ^Crockford, Douglas (11 September 2001)."JSMin: The JavaScript Minifier".Crockford.com.Self-published. Archived fromthe original on 5 April 2002.
  2. ^ab"Code minification".webplatform.github.io. The WebPlatform Project.Archived from the original on 24 April 2016.
  3. ^Paul, Ryan (6 November 2009)."Google opens up its JavaScript development toolbox to all".Ars Technica.
  4. ^Bazon, Mihai (8 November 2012)."Should you switch to UglifyJS2?".lisperator.net.Self-published.
  5. ^"uglify-js NPM".npmjs.com. 6 May 2017.
  6. ^"terser · JavaScript mangler and compressor toolkit for ES6+".terser.org. Retrieved29 January 2023.
  7. ^"Update README.md · terser/terser@3ef6879".GitHub.
  8. ^"Terser vs uglify-js".NPM trends.Archived from the original on 27 January 2024.
  9. ^Santos, Fábio (December 28, 2018)."Update README.md - terser/terser@b2e0736".GitHub. Retrieved2026-01-23.
  10. ^ab"Source Map Revision 3 Proposal". 11 January 2011. Archived fromthe original on 8 March 2016. Retrieved16 April 2016.
  11. ^Seddon, Ryan (21 March 2012)."Introduction to JavaScript Source Maps".HTML5 Rocks. Archived fromthe original on 28 December 2021.
Retrieved from "https://en.wikipedia.org/w/index.php?title=Minification_(programming)&oldid=1339127183"
Categories:
Hidden categories:

[8]ページ先頭

©2009-2026 Movatter.jp