- javascriptcompressor.com (在线压缩)
- shrinksafe.dojotoolkit.org (在线文件压缩)
- dean.edwards.name/packer (在线压缩)
- YUI Compressor (使用命令行来压缩,需要JAVA虚拟机来运行压缩程序)
- JSmin (提供下载,非常好用)
强烈推荐JSmin,服务的很周到,JSmin包括C,C#,Java,JavaScript,Perl,PHP,Python,OCAML还有Ruby的源文件,提供下载下来使用。
javascript(js)代码压缩工具-jsmin 使用方法
官方地址:http://www.crockford.com/javascript/jsmin.html
点击页下方的”zip file containing an MS-DOS.exe file“下载。
运行-cmd-输入:D:\jsmin\jsmin.exe <D:jsmin\jsfile.js>D:\jsmin\jsfile_new_name.js
但是按照官方的方法没试成功,即运行jsmin.exe,输:jsmin <test.js>small_test.js 没反应???
(jsmin.exe和test.js位于同一目录下,生成的目标文件取名small_test.js)
不知道什么原因!!?于是只好cmd一下,输:D:\jsmin\jsmin.exe <D:jsmin\test.js>D:\jsmin\small_test.js (文件都放在D:\jsmin目录下)
才O了
javascript 压缩工具 yui compressor
减小javascript及css文件大小可以加快浏览器下载,达到页面提速。所以选择一款好的javascript压缩工具,很重要。在对比了几款工具后,选择集中在dojo的shrinksafe和雅虎的yui compressor上,两款都不错,但是dojo存在安全方面的问题,比如他通过把函数及变量已简写的数字字母方式来达到压缩。所以我选择yui compressor,它支持js及css文件,还可以设定charset,速度和压缩率都令人满意。具体用法,先看看help。
java -jar yuicompressor-2.3.5.jar --help Usage: java -jar yuicompressor-x.y.z.jar [options] [input file] Global Options -h, --help Displays this information --type <js|css> Specifies the type of the input file --charset <charset> Read the input file using <charset> --line-break <column> Insert a line break after the specified column number -v, --verbose Display informational messages and warnings -o <file> Place the output into <file>. Defaults to stdout. JavaScript Options --nomunge Minify only, do not obfuscate --preserve-semi Preserve all semicolons --disable-optimizations Disable all micro optimizations If no input file is specified, it defaults to stdin. In this case, the 'type' option is required. Otherwise, the 'type' option is required only if the input file extension is neither 'js' nor 'css'.
压缩例子
java -jar yuicompressor-2.3.5.jar –type js unc.flag.js -o flag.js
文件的类型可以不加,yuicompressor 会自动判断转换类型。