Usuario:Awacaton/Taller

De Wikipedia, la enciclopedia libre

Minificación (también minimización), en lenguaje de computación especialmente JavaScript, es un proceso en el cual se remueve todos los caracteres innecesarios del código fuente sin afectar su funcionalidad. Algunos de los caracteres necesarios incluyen: 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.

Reducir fuente de código es especialmente útil para interpretar lenguaje desplegado y transmitirlo en Internet (como JavaScript), por que reduce grandes cantidades de datos que se necesitan para ser transferidos al servidor. La minimización de código fuente también es usado como un tipo de ofuscación, 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.

Example[editar]

For example the JavaScript script

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

is equivalent to but longer than

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

History[editar]

In 2003 Douglas Crockford introduced 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[editar]

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]

Types[editar]

Tools[editar]

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.[cita requerida] 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 BlimptonTech.com.[13]

Web development[editar]

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.[cita requerida]

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.[cita requerida]

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

References[editar]

  1. JSMin. Crockford.com (4 December 2003).
  2. a b «minification · concepts · WPD · WebPlatform.org». docs.webplatform.org. Consultado el 11 de abril de 2016. 
  3. «Google opens up its JavaScript development toolbox to all». Ars Technica. Consultado el 11 de abril de 2016. 
  4. Bazon, Mihai. «Should you switch to UglifyJS2?». lisperator.net. Consultado el 11 de abril de 2016. 
  5. a b «Source Map Revision 3 Proposal». Google Docs. Consultado el 16 de abril de 2016. 
  6. Microsoft Ajax Minifier. Ajaxmin.codeplex.com (13 September 2012).
  7. Pretty Diff. Pretty Diff.
  8. HtmlCompressor. code.google.com/archive/p/htmlcompressor (11 February 2017).
  9. HTMLMinifier. github.com/kangax/html-minifier (11 February 2017).
  10. WebMarkupMin. github.com/Taritsyn/WebMarkupMin (11 February 2017).
  11. minifyPS. Minifyps.codeplex.com (22 February 2012).
  12. Online JS Minify
  13. BlimptonTech. BlimptonTech.com (17 July 2013).
  14. http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/