使用指令处理JS、CSS、PNG文件

本文介绍了如何使用YUI压缩工具压缩JS和CSS文件,通过YMIN脚本实现批量处理。同时,提供了一个使用JavaScriptLint检查JavaScript文件的方法,确保代码质量。此外,还介绍了PNGOUT工具用于压缩PNG图片,减少文件大小而不损失质量。这些技术对于优化网站加载速度和资源管理非常有用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

[b]使用yui的压缩工具压缩JS和CSS[/b]
[url]http://developer.yahoo.com/yui/compressor/[/url]
yuicompressor.jar这个文件要和ymin这个文件放在一个目录下。
ymin的代码如下

#!/bin/sh
#filename=ymin
basedir=$(dirname $0)
jsmin="java -jar $basedir/yuicompressor.jar --type js"
cssmin="java -jar $basedir/yuicompressor.jar --type css"
for f in $*; do
case $f in
*.source.js)
n=`echo $f | sed s/.source.js$//`
$jsmin $f -o $n.js ;;
*.js)
n=`echo $f | sed s/.js$//`
$jsmin $f -o $n-min.js ;;
*.source.css)
n=`echo $f | sed s/.source.css$//`
$cmd;$cssmin $f -o $n.css ;;
*.css)
n=`echo $f | sed s/.css$//`
$cssmin $f -o $n-min.css ;;
*)
find $f -exec ymin {} ';';;
esac
done


使用示例

ymin a.js
#生成 a-min.js
ymin a.source.js
#生成 a.js
ymin *.js
#依上两个规则批量处理find *.js查找到文件

压缩CSS就 不举例了


[b]使用javascript lint检查js文件[/b]
[url]http://www.javascriptlint.com/[/url]
mac用户可使用brew install jsl安装

#!/bin/sh
#filename=jslt
option="-nologo"
for f in $*; do
case $f in
*.js)
jsl $option -process $f;;
-*)
option="$option $f";;
*)
find $f -exec jsl $option {} ';';;
esac
done


使用示例

jslt a.js
jslt *.js
jslt -nocontext *.js


使用PNGOUT压缩文件
[url]http://advsys.net/ken/utils.htm[/url]
这个只列下帮助吧,我没有用SHELL再包了

$ pngout --help
Warning: unrecognized option: --help
Must specify a source or target image
PNGOUT [In:{PNG,JPG,GIF,TGA,PCX,BMP}] (Out:PNG) (options...) Jul 22 2011
by Ken Silverman (http://advsys.net/ken)
Mac port assistance by Jonathon Fowler (http://www.jonof.id.au/pngout)
PNGOUT optimizes PNG size losslessly using my own deflate algorithm (not Zlib)
With the right options, it can often beat other programs by 5-10%. Options:
-c# PNG output color: 0=Gray, 2=RGB, 3=Pal, 4=Gray+Alpha, 6=RGB+Alpha
-f# PNG output filter: 0=none, 1=x, 2=y, 3=x&y, 4=Paeth, 5=mixed, 6=reuse
-d# Override default bitdepth: 0(min),1,2,4,8 (valid only in /c0,/c3 modes)
-s# Select strategy. 0:Xtreme(default), 1:Intense, 2:Longest Match,
3:Huffman Only, 4:Uncompressed
-b# Block split threshold (lower=more blocks, 0=1 block/file, default=256)
Use trial&error! Suggested values to try are: 0,128,192,256,512,1024,..
-n# Exact number of Huffman blocks (overrides /b#)
-r Randomized initial tables (good for many trials with same options)
-k? 0=Remove optional chunks (default), 1=Keep all
p=Keep palette indices, s=Keep settings for /c,f,d,b
-k(Chunk,Chunk,..) Preserve only named chunk(s). Example: -kgAMA,bKGD,tEXt
-v,q,l Verbose,Quiet,List mode (use '-' as filename to specify stdin/stdout)
-y Assume Yes at the 'overwrite file?' prompt
-force Write file even if bigger.
-mincodes# Workaround for buggy decoders. 1:Zlib 1.2.1 bug, 2:buggy mobiles
The 1st filename is the input. If you omit the output
filename, PNGOUT will use the same filename with a .PNG extension. Examples:
$ pngout inlarge.bmp outsmall.png <- writes outsmall.png
$ pngout duke3d.png -c2 -f3 -b128 -kbKGD -v <- writes duke3d.png if smaller
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值