YUI Compressor
之前说到了JSLint,不过在实际的工作中间到底是否能够完全遵循标准来实现就是另一说了.
According to Yahoo!’s Exceptional Performance Team, 40% to 60% of Yahoo!’s users have an empty cache experience and about 20% of all page views are done with an empty cache (see this article by Tenni Theurer on the YUIBlog for more information on browser cache usage). This fact outlines the importance of keeping web pages as lightweight as possible. Improving the engineering design of a page or a web application usually yields the biggest savings and that should always be a primary strategy. With the right design in place, there are many secondary strategies for improving performance such as minification of the code,HTTP compression, using CSS sprites, etc.
根据yahoo性能小组的调查,yahoo的访问者中有40%到60%的用户在访问yahoo页面的时候是没有缓存的.而20%的页面是在没有缓存的情况下加载的.这个结果就说明了把一个页面尽可能做得轻量级是多么的重要.所以设计师提高一个页面的设计质量或者一个web工程,对于提高性能来说是一个很好的策略.有了适当的设计,然后还有很多的二级策略来提高性能.例如最小化代码,HTTP压缩,使用css sprites等.
In terms of code minification, the most widely used tools to minify JavaScript code are Douglas Crockford’s JSMIN, the Dojo compressor and Dean Edwards’ Packer. Each of these tools, however, has drawbacks. JSMIN, for example, does not yield optimal savings (due to its simple algorithm, it must leave many line feed characters in the code in order not to introduce any new bugs).
对于最小化代码,常用到的工具就是来压缩Javascript代码,例如Douglas Crockford 的JSMIN,还有Dojo压缩,Dean Edward的Packer,不过这些工具都有一些硬伤,例如JSMIN,不能够做到完全的节约,由于他的简单的算法,为了不产生一些新的bug而不得不余留一些换行在代码中.
The goal of JavaScript and CSS minification is always to preserve the operational qualities of the code while reducing its overall byte footprint (both in raw terms and after gzipping, as most JavaScript and CSS served from production web servers is gzipped as part of the HTTP protocol). The YUI Compressor is JavaScript minifier designed to be 100% safe and yield a higher compression ratio than most other tools. Tests on the YUI Library have shown savings of over 20% compared to JSMin (becoming 10% after HTTP compression). The YUI Compressor is also able to compress CSS files by using a port of Isaac Schlueter‘s regular-expression-based CSS minifier.