js压缩工具

本文介绍了几种流行的JavaScript代码压缩工具,包括在线压缩工具和使用命令行的工具,并提供了具体的使用方法和比较分析。
  1. javascriptcompressor.com (在线压缩)
  2. shrinksafe.dojotoolkit.org (在线文件压缩)
  3. dean.edwards.name/packer (在线压缩)
  4. YUI Compressor (使用命令行来压缩,需要JAVA虚拟机来运行压缩程序)
  5. 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 会自动判断转换类型。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值