做这个THEME时用到的prototype.js有124KB,相当的大,经过压缩后只有50KB,效果还是相当明显.

下面我们介绍这个工具:ESC(ECMAScript cruncher)来帮我们完成这个工作,不过这个工具只能在Windows下使用.到http://www.saltstorm.net/depo/.....wbm?pod=js下载ESC.zip,解压后看看它的帮助文档.很简单.

压缩级别分为5种,从0到4

在WINDOWS命令行下执行

———————————————————–
Usage :
ESC.wsf -l [0-4] -ow output.js foo.js bar.js C:\scripts\baz
———————————————————–
-a  [-about]             : Description page
-c  [-copyright]         : Copyright/license notice
-e  [-example]           : Examples of usage
-h  [-help]              : This help-screen
———————————————————–
-l  [-level]   [01(2)34] : [optional] Set crunch-level (4 sets -$ on)
-s  [-silent]            : [optional] Run silent, nada stdout
-v  [-verbose]           : [optional] Run in verbose mode
-$                       : [optional] Activate variable-substitution engine
———————————————————–
-oa <filename>           : Target filename for appending
-ow <filename>           : Target filename for writing
-ow STDOUT               : Write stream to STDOUT
———————————————————–
<input-file(s)>           : [required]
file(s) and/or directories containing scripts to crunch…
(If filenames contains spaces, they must be quoted)

需要注意的是,js压缩级别4会把变量名修改,如果你的js中用到了全局变量或者类的话,就不能使用该压缩级别了,否则其它使用你的js的文件可能会无法正常运行.

还有几个在线的压缩工具,也相当不错.