天天看點

TBCompressor - JS和CSS壓縮工具

轉自歲月如歌的http://lifesinger.org/blog/?p=464

有朋友問到淘寶是怎麼壓縮js和css的,這裡分享下。

我們使用的是YUI Compressor:

The YUI Compressor is a JavaScript compressor which, in addition to removing comments and white-spaces, obfuscates local variables using the smallest possible variable name. This obfuscation is safe, even when using constructs such as ‘eval’ or ‘with’ (although the compression is not optimal is those cases) Compared to jsmin, the average savings is around 20%.

The YUI Compressor is also able to safely compress CSS files. The decision on which compressor is being used is made on the file extension (js or css)

淘寶前端的開發環境以Windows居多。為了友善使用,對YUICompressor做了層簡單的封裝,稱之為TBCompressor. 安裝和使用方法如下:

安裝說明

  1. 安裝請點選install.cmd
  2. 解除安裝請點選uninstall.cmd
  3. 如果以前安裝過2.3.5之前的版本, 請點選update.cmd更新

測試使用

  1. 在test.source.js上右鍵,執行菜單“壓縮JavaScript”,會生成test.js檔案。如果再對test.js檔案執行一次壓縮,會生成test-min.js檔案
  2. CSS同1

下載下傳試用

TBCompressor_v2.4.zip (1.53 MB)

繼續閱讀