Closure Compiler vs YUICompressor

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

5 comments

Comments 1 - 5 of 5 previous next Post a comment

Post a comment
Embed Video
Edit your comment Cancel

25 Favorites

Closure Compiler vs YUICompressor - Presentation Transcript

  1. Google Closure Compiler vs. YUI Compressor lifesinger@gmail.com 2009-11-09
  2. Who’s this guy? http://lifesinger.org/
  3. Players • GC = Google Closure Compiler http://code.google.com/p/closure-compiler/
  4. Players • YC = YUI Compressor http://yuilibrary.com/downloads/#yuicompressor
  5. Optimization Levels ① Whitespace Level ② Simple Optimizations ③ Advanced Optimizations
  6. Whitespace
  7. Whitespace Level • Remove comments • Remove extra white space • Remove unneccessary semicolon GC YC
  8. Simple Optimizations
  9. Simple Optimizations • var varName = “”  var a = “” • object[“property”]  object.property • {“key” : “val”}  {key : “val”} • „xi‟an‟  “xi‟an” • “I am ” + “hot”  “I am hot” GC YC
  10. Simple Optimizations • a = new Object  a = {} • a = new Array  a = [] • if(a) b()  a && b() • if(a) b(); else c()  a ? b() : c() • if(1) b(); else c()  b() • return 2 * 3;  return 6; • return undefined;  return; • var f = function(){}  function f(){} • var a; var b;  var a, b; • … GC YC
  11. Simple Optimizations • Simple dead code removal GC YC
  12. Advanced Optimizations
  13. Advanced Optimizations • Dead code removal & Function inlining GC YC
  14. Advanced Optimizations • Aggressive renaming GC unsafe
  15. Advanced Optimizations • More amazing but unsafe advanced optimizations: http://code.google.com/closure/compiler/docs /api-tutorial3.html#better
  16. Whitespace Level Simple Level Advanced Level GC YC Basic
  17. Helping Compressors
  18. Helping Compressors ① Use local variables to store: 1. Repeated primitive values 2. Global variables 3. Object properties Good practices for YC and GC both.
  19. Helping Compressors ② Try to have only one var statement: Good practice for YC. Unneccessary for GC.
  20. Hurting Compressors
  21. Hurting Compressors ① eval() is Evil. GC YC
  22. Hurting Compressors ② with statement considered harmful. GC YC
  23. Hurting Compressors ③ Jscript conditional comments
  24. Hurting Compressors  Solutions: - Solution #1: Don’t use - Solution #2: See Solution #1
  25. Sugar
  26. Comments • Preserve some comments: YC
  27. Annotation Check http://code.google.com/closure/compiler/docs/js-for-compiler.html GC
  28. File Combination java -jar compiler.jar --js=in1.js --js=in2.js ... --js_output_file=out.js GC
  29. native2ascii • GC works well for utf-8 encoding files. • YC doesn’t have this feature.
  30. native2ascii YC + native2ascii command script:
  31. native2ascii GC script for GB18030 encoding files: Suggest GC to support: --charset GB18030
  32. CSS Compression • YC is good! • GC comes on!!!
  33. Compression Rates
  34. Summary • YC is more reliable. • GC is amazing, and almost safe at simple optimization level. • GC is promising, but unsafe at advanced optimization level.
  35. References • http://www.slideshare.net/nzakas/extreme- javascript-compression-with-yui- compressor • http://stackoverflow.com/questions/168642 8/should-i-use-the-yui-compressor-or-the- new-google-closure-compiler-to-compress- my • http://news.ycombinator.com/item?id=924 426
  36. Thanks!
SlideShare Zeitgeist 2009

+ lifesingerlifesinger Nominate

custom

4667 views, 25 favs, 32 embeds more stats

More info about this document

© All Rights Reserved

Go to text version

  • Total Views 4667
    • 1329 on SlideShare
    • 3338 from embeds
  • Comments 5
  • Favorites 25
  • Downloads 53
Most viewed embeds
  • 1592 views on http://ued.taobao.com
  • 1214 views on http://lifesinger.org
  • 339 views on http://www.cnblogs.com
  • 38 views on http://discussions.zoho.com
  • 23 views on http://www.zhuaxia.com

more

All embeds
  • 1592 views on http://ued.taobao.com
  • 1214 views on http://lifesinger.org
  • 339 views on http://www.cnblogs.com
  • 38 views on http://discussions.zoho.com
  • 23 views on http://www.zhuaxia.com
  • 16 views on http://www.alibuybuy.com
  • 16 views on http://blog.ohthink.com
  • 15 views on http://www.danielwang.cn
  • 14 views on http://xianguo.com
  • 9 views on http://reader.youdao.com
  • 7 views on http://zhuaxia.com
  • 6 views on http://static.slidesharecdn.com
  • 6 views on https://discussions.zoho.com
  • 6 views on http://cache.baidu.com
  • 5 views on http://sr.ju690.com
  • 4 views on http://farhadi.ir
  • 4 views on file://
  • 3 views on http://d.zoho.com
  • 3 views on http://blog.yuing.cn
  • 3 views on http://www.ohthink.com
  • 2 views on http://192.168.1.3:1300
  • 2 views on http://translate.googleusercontent.com
  • 2 views on http://discussion.zoho.com
  • 1 views on http://203.208.39.132
  • 1 views on http://www.txtall.cn
  • 1 views on http://kb.cnblogs.com
  • 1 views on http://m.cnblogs.com
  • 1 views on http://m134.mail.qq.com
  • 1 views on http://m372.mail.qq.com
  • 1 views on http://mailreadertest.163.com
  • 1 views on http://www.discussions.zoho.com
  • 1 views on http://www.hanrss.com

less

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

Cancel
File a copyright complaint
Having problems? Go to our helpdesk?

Categories