六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 193|回复: 0

js压缩工具

[复制链接]

升级  10.75%

389

主题

389

主题

389

主题

探花

Rank: 6Rank: 6

积分
1215
 楼主| 发表于 2013-2-8 00:01:13 | 显示全部楼层 |阅读模式
 
强烈推荐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。
<div class="wp_syntax" style="padding-bottom: 0px;"><div class="code">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 inputfile extension is neither 'js' nor 'css'.
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表