TBCompressor – JS和CSS压缩工具
有朋友问到淘宝是怎么压缩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. 安装和使用方法如下:
安装说明
- 安装请点击install.cmd
- 卸载请点击uninstall.cmd
- 如果以前安装过2.3.5之前的版本, 请点击update.cmd升级
测试使用
- 在test.source.js上右键,执行菜单“压缩JavaScript”,会生成test.js文件。如果再对test.js文件执行一次压缩,会生成test-min.js文件
- CSS同1

October 22nd, 2008 on 19:00
非常实用的工具, 收之.
October 23rd, 2008 on 13:20
好东西啊
October 25th, 2008 on 20:30
[...] TBCompressor —— 淘宝UED的JS/CSS压缩工具,详见玉伯的介绍 [...]
October 30th, 2008 on 1:19
使用提示请先安装JDK并添加JAVA_HOME环境变量
请问怎么操作呢?
Java我已经安装了,freemind等Java软件正常运行。
October 30th, 2008 on 13:23
有没有 for linux 的版本?
October 30th, 2008 on 13:35
我回贴不看贴了…… YUICompressor 本来就是跨平台的……
November 17th, 2008 on 16:53
请问一下!这个直接就可以运行吗?为什么我一运行就显示”请先安装JDK并添加JAVA_HOME环境变量”
November 23rd, 2008 on 12:40
我想问一下有不有可以解压的工具,使得看JS代码不那么累!
November 24th, 2008 on 9:16
@black: 有一个反压缩工具,很不错 http://elfz.laacz.lv/beautify/
December 12th, 2008 on 21:24
谢谢,我压缩了一个.
http://www.buyecity.com
December 15th, 2008 on 15:49
正在找呢,谢谢。
December 28th, 2008 on 5:45
[...] 淘宝做了一个可视化的版本,叫做TBCompressor,可以到这里下载:http://lifesinger.org/blog/?p=464 谢谢岁月老大! [...]
December 28th, 2008 on 12:01
为什么我直接生成的test.source-min.css呢?
http://img201.imageshack.us/my.php?image=20081228115618ns9.png
压缩直接出错
http://img258.imageshack.us/my.php?image=20081228120221yj0.png
在w2k3英文版里面出错,xp中文使用正常
December 28th, 2008 on 12:02
压缩js直接出错
http://img258.imageshack.us/my.php?image=20081228120221yj0.png
刚才的回复,少打了js两个字母。
January 4th, 2009 on 16:00
以上脚本,简单的修改了一下。
增加了【显示压缩前后文件大小】
把 native2ascii.exe 的处理部分,注释掉了,需要的自己打开。
把 YUI 的 所有的 JAR 文件放在 YUI 目录中。直接执行这个批处理进行安装。
March 17th, 2009 on 12:01
下载不了。
April 22nd, 2009 on 14:54
是不是需要先安装java虚拟机啊
October 27th, 2009 on 17:31
支持!
@网络监控 需要java 虚拟机
leave a reply