随笔-57  评论-129  文章-0  trackbacks-0
刚刚修正了一个JSA的bug。

顺便测试了一下文本压缩的性能,和纯packer 压缩,ShrinkSafe+packer压缩。
压缩大小:
jquery-jsa-s.js(JSA的语法压缩):29766
jquery.compressed.js(ShrinkSafe语法压缩):33992

jquery-jsa-st.js(JSA的语法压缩+文本压缩):19526
jquery-packer.js(Packer文本压缩):20977
jquery.compressed-packer.js(ShrinkSafe语法压缩+Packer文本压缩):21839

有点奇怪的是,文本压缩和语法压缩是有一定互补性的,但是ShrinkSafe+Packer比单纯的Packer文本压缩效率还低??
我想可能是ShrinkSafe做的一些语法补全(可省略的 {、}、;、),jQuery编码的风格导致。

Firefox测试数据(10次压缩时间的毫秒数,连续5回测试数据)

jquery-jsa-st.js:784
jquery-packer.js:1265
jquery.compressed-packer.js:1529

jquery-jsa-st.js:718
jquery-packer.js:922
jquery.compressed-packer.js:766

jquery-jsa-st.js:753
jquery-packer.js:872
jquery.compressed-packer.js:828

jquery-jsa-st.js:1438
jquery-packer.js:1484
jquery.compressed-packer.js:1735

jquery-jsa-st.js:687
jquery-packer.js:1236
jquery.compressed-packer.js:1234


IE5 测试数据(连续三回测试数据)

jquery-jsa-st.js:766
--------------------------------------------------------------------------------
jquery-packer.js:9765
--------------------------------------------------------------------------------
jquery.compressed-packer.js:10547


jquery-jsa-st.js:671
--------------------------------------------------------------------------------
jquery-packer.js:9002
--------------------------------------------------------------------------------
jquery.compressed-packer.js:10265


jquery-jsa-st.js:704
--------------------------------------------------------------------------------
jquery-packer.js:8232
--------------------------------------------------------------------------------
jquery.compressed-packer.js:10314

总结

文本压缩是个比较耗时的操作,像JQuery这样大的类库普遍需要接近100毫秒的解压时间。
如果需要兼容IE5这种老古董,那么最好不要用packer的文本压缩,太耗时。
JSA1 对文本压缩做了些改进,表现还可以。

如果要计较脚本文本压缩后的解压开销,建议使用JSA的语法压缩,配合服务器端的gzip压缩。
不推荐dojo 的ShrinkSafe,原因是它的几个安全问题。
posted on 2007-05-24 09:28 金大为 阅读(936) 评论(0)  编辑  收藏 所属分类: JavaScript

只有注册用户登录后才能发表评论。


网站导航: