Minification (programming)

From Wikipedia, the free encyclopedia
Jump to: navigation, 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 Perl culture, aiming at extremely minified source code is the purpose of the Perl golf game.

Minified source code is also very useful for HTML code. As an example, successive whitespace characters in HTML are rendered as a single space, so replacing all whitespace sequences with single spaces can considerably reduce the size of a page.

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.

Types[edit]

Tools[edit]

JavaScript optimizers such as JSMin[1] and Packer[2] are specially designed for modern web programming techniques, and are able to understand and preserve conditional comments, and similar. Packer, for instance, can optionally Base64 compress the given source code in a manner that can be decompressed by regular web browsers, as well as shrink variable names that are typically 5–10 characters to single letters, which reduces the file size of the script and, therefore, makes it download faster.[3] Google has released their Closure Compiler, which also provides minification as well as the ability to introduce more aggressive renaming, removing dead code, and providing function inlining.[4] In addition, certain online tools, such as Microsoft Ajax Minifier,[5] the Yahoo! YUI Compressor or Pretty Diff,[6] can compress CSS files.[citation needed] There is a PowerShell script named "minifyPS"[7] that is able to shrink PowerShell script code as well as JavaScript code. There is a free online tool that can minify JS[8] with UglifyJS and has the ability to combine multiple files at BlimptonTech.com.[9]

Web development[edit]

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

JavaScript and CSS resources may be minified, preserving their behavior while considerably reducing their file size. The Closure Tools project is an effort by Google engineers to open source the tools used in many of Google's sites and web applications for use by the wider Web development community. Closure Compiler compiles JavaScript into compact, high-performance code, and can perform aggressive global transformations in order to achieve high compression and advanced optimization. Other libraries available online are also capable of minification and optimization to varying degrees.

Some libraries also merge multiple script files into a single file for client download. This fosters a modular approach to development.[citation needed]

A novel approach to server-side minification is taken by Ziproxy, a forwarding, non-caching, compressing HTTP proxy targeted for traffic optimization. It minifies and optimizes HTML, CSS, and JavaScript resources and, in addition, re-compresses pictures.

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.

An alternative to content encoding in the server-client layer is given by the off-line CrunchMe tool, which can create self extracting JavaScript programs using the DEFLATE compression algorithm.[citation needed]

JavaScript source maps can make code readable and more importantly debuggable even after it has been combined and minified.[10]

References[edit]

  1. ^ JSMin. Crockford.com (4 December 2003).
  2. ^ Packer. Dean.edwards.name.
  3. ^ Packer version 3.0 feature list. Dean.edwards.name.
  4. ^ Google Closure Compiler. Code.google.com (2 July 2012).
  5. ^ Microsoft Ajax Minifier. Ajaxmin.codeplex.com (13 September 2012).
  6. ^ Pretty Diff. Pretty Diff.
  7. ^ minifyPS. Minifyps.codeplex.com (22 February 2012).
  8. ^ Online JS Minify
  9. ^ BlimptonTech. BlimptonTech.com (17 July 2013).
  10. ^ http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/