Minification (programming)

From Wikipedia, the free encyclopedia
  (Redirected from Minify)
Jump to navigation Jump to search

Minification (also minimisation or minimization), in computer programming languages and especially JavaScript, is the process of removing all unnecessary characters from source code 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.

Minified source code is especially useful for interpreted languages deployed and transmitted on the Internet (such as JavaScript), because it reduces the amount of data that needs to be transferred. Minified source code may also be used as a kind of obfuscation, though the term obfuscation may be distinguished as a form of false cryptography while a minified code instance may be reversed using a pretty-printer. 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.


For example the JavaScript script

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);


In 2003 Douglas Crockford introduced the tool JSMin,[1] which only removed comments and whitespace.[2] It was followed by YUI Compressor shortly thereafter.[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]

Source mapping[edit]

Source maps allow tools to display unminified code from minified code with an optimized "mapping" between them. The original format was created by Joseph Schorr as part of the Closure Inspector minification project.[5] Updates as versions 2 and 3 reduced the size of the map files.[5]



JavaScript optimizers which can minify and generate source maps include UglifyJS and Google's Closure Compiler.

In addition, certain online tools, such as Microsoft Ajax Minifier,[6] the Yahoo! YUI Compressor or Pretty Diff,[7] can compress CSS files.[citation needed] For minification of HTML code there are the following tools: HtmlCompressor,[8] HTMLMinifier[9] and WebMarkupMin.[10] There is a PowerShell script named "minifyPS"[11] that is able to shrink PowerShell script code as well as JavaScript code. There is a free online tool that can minify JS[12] with UglifyJS and has the ability to combine multiple files at[13]

Web development[edit]

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.[14]

Content encoding is an approach taken by compatible web servers and modern web browsers to compress HTML and related textual content, often in the gzip format.[clarification needed]


  1. ^ JSMin. (4 December 2003).
  2. ^ a b "minification · concepts · WPD ·". Archived from the original on 24 April 2016. Retrieved 11 April 2016.
  3. ^ "Google opens up its JavaScript development toolbox to all". Ars Technica. Retrieved 2016-04-11.
  4. ^ Bazon, Mihai. "Should you switch to UglifyJS2?". Retrieved 2016-04-11.
  5. ^ a b "Source Map Revision 3 Proposal". Google Docs. Retrieved 2016-04-16.
  6. ^ Microsoft Ajax Minifier. (13 September 2012).
  7. ^ Pretty Diff. Pretty Diff.
  8. ^ HtmlCompressor. (11 February 2017).
  9. ^ HTMLMinifier. (11 February 2017).
  10. ^ WebMarkupMin. (11 February 2017).
  11. ^ minifyPS. (22 February 2012).
  12. ^ Online JS Minify
  13. ^ BlimptonTech. (17 July 2013).
  14. ^

External Links[edit]

Minify CSS