SlideShare a Scribd company logo
Google Closure Compiler
          vs.
   YUI Compressor

    lifesinger@gmail.com
          2009-11-09
Who’s this guy?


      http://lifesinger.org/
Players

• GC = Google Closure Compiler




  http://code.google.com/p/closure-compiler/
Players

• YC = YUI Compressor




   http://yuilibrary.com/downloads/#yuicompressor
Optimization Levels


① Whitespace Level
② Simple Optimizations
③ Advanced Optimizations
Whitespace
Whitespace Level
• Remove comments
• Remove extra white space
• Remove unneccessary semicolon




                                  GC
                                  YC
Simple Optimizations
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
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
Simple Optimizations
• Simple dead code removal




                              GC
                              YC
Advanced Optimizations
Advanced Optimizations
• Dead code removal & Function inlining




                                    GC
                                    YC
Advanced Optimizations
• Aggressive renaming




                         GC
                              unsafe
Advanced Optimizations
• More amazing but unsafe advanced
  optimizations:
http://code.google.com/closure/compiler/docs
  /api-tutorial3.html#better
Whitespace Level   Simple Level   Advanced Level


GC


YC
                           Basic
Helping Compressors
Helping Compressors
① Use local variables to store:
  1. Repeated primitive values
  2. Global variables
  3. Object properties




           Good practices for YC and GC both.
Helping Compressors
② Try to have only one var statement:




             Good practice for YC.
            Unneccessary for GC.
Hurting Compressors
Hurting Compressors
① eval() is Evil.


                    GC

                    YC
Closure Compiler vs YUICompressor
Hurting Compressors
② with statement considered harmful.


                    GC


                  YC
Closure Compiler vs YUICompressor
Hurting Compressors
③ Jscript conditional comments
Hurting Compressors
 Solutions:
   - Solution #1: Don’t use
   - Solution #2: See Solution #1
Sugar
Comments
• Preserve some comments:




                            YC
Annotation Check



http://code.google.com/closure/compiler/docs/js-for-compiler.html



                                     GC
File Combination

java -jar compiler.jar
          --js=in1.js --js=in2.js ...
          --js_output_file=out.js




                         GC
native2ascii
• GC works well for utf-8 encoding files.
• YC doesn’t have this feature.
native2ascii
YC + native2ascii command script:
native2ascii
GC script for GB18030 encoding files:




Suggest GC to support:   --charset GB18030
CSS Compression
• YC is good!
• GC comes on!!!
Compression Rates
Summary
• YC is more reliable.

• GC is amazing, and almost safe at simple
  optimization level.

• GC is promising, but unsafe at advanced
  optimization level.
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
Thanks!

More Related Content

PPTX
CI / CD with Nomad
PPTX
DOM & Events
PDF
PhoneGap in a Day
PDF
WPO @ PubCon 2010
KEY
Phonegap for Engineers
PPTX
Static resource-optimization using webutilities
PDF
本当のClosure Compilerをお見せしますよ。
PDF
New Algorithms in Java
CI / CD with Nomad
DOM & Events
PhoneGap in a Day
WPO @ PubCon 2010
Phonegap for Engineers
Static resource-optimization using webutilities
本当のClosure Compilerをお見せしますよ。
New Algorithms in Java

Similar to Closure Compiler vs YUICompressor (20)

PPTX
OptView2 MUC meetup slides
PPTX
GCC Summit 2010
PDF
The Performance Engineer's Guide to Java (HotSpot) Virtual Machine
PDF
Eclipse Day India 2015 - Java bytecode analysis and JIT
PDF
Pharo Virtual Machine: News from the Front
PDF
Lifecycle of a JIT compiled code
PDF
How the HotSpot and Graal JVMs execute Java Code
PDF
Tips and tricks for building high performance android apps using native code
PPTX
JVM @ Taobao - QCon Hangzhou 2011
PPTX
Clr jvm implementation differences
PDF
자바를 잡아주는 GURU가 있다구!? - 우여명 (아이스크림에듀) :: AWS Community Day 2020
PDF
淺談 Java GC 原理、調教和 新發展
PDF
Personalized Defect Prediction
PDF
Extreme JavaScript Compression With YUI Compressor
PDF
Sista: Improving Cog’s JIT performance
PDF
SECON'2017, Цаль-Цалко Иван, Go на практике
PDF
2013 syscan360 yuki_chen_syscan360_exploit your java native vulnerabilities o...
PDF
Slices Of Performance in Java - Oleksandr Bodnar
PDF
PAC 2019 virtual Philip Webb
PDF
WSDM Cup 2017: Vandalism Detection
OptView2 MUC meetup slides
GCC Summit 2010
The Performance Engineer's Guide to Java (HotSpot) Virtual Machine
Eclipse Day India 2015 - Java bytecode analysis and JIT
Pharo Virtual Machine: News from the Front
Lifecycle of a JIT compiled code
How the HotSpot and Graal JVMs execute Java Code
Tips and tricks for building high performance android apps using native code
JVM @ Taobao - QCon Hangzhou 2011
Clr jvm implementation differences
자바를 잡아주는 GURU가 있다구!? - 우여명 (아이스크림에듀) :: AWS Community Day 2020
淺談 Java GC 原理、調教和 新發展
Personalized Defect Prediction
Extreme JavaScript Compression With YUI Compressor
Sista: Improving Cog’s JIT performance
SECON'2017, Цаль-Цалко Иван, Go на практике
2013 syscan360 yuki_chen_syscan360_exploit your java native vulnerabilities o...
Slices Of Performance in Java - Oleksandr Bodnar
PAC 2019 virtual Philip Webb
WSDM Cup 2017: Vandalism Detection
Ad

More from lifesinger (9)

PDF
SeaJS 那些事儿
PDF
SeaJS - 前端模块化开发探索与网站性能优化实践
PDF
开放式类库的构建
PDF
让开发也懂前端
PDF
SeaJS - 跨环境模块化开发实践
KEY
Intro-to-SeaJS
PDF
Progressive Enhancement
PDF
KISSY Mechanism
PPTX
The Beauty Of Refactoring
SeaJS 那些事儿
SeaJS - 前端模块化开发探索与网站性能优化实践
开放式类库的构建
让开发也懂前端
SeaJS - 跨环境模块化开发实践
Intro-to-SeaJS
Progressive Enhancement
KISSY Mechanism
The Beauty Of Refactoring
Ad

Recently uploaded (20)

PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
sap open course for s4hana steps from ECC to s4
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
cuic standard and advanced reporting.pdf
PDF
Approach and Philosophy of On baking technology
PPT
Teaching material agriculture food technology
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Empathic Computing: Creating Shared Understanding
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
Building Integrated photovoltaic BIPV_UPV.pdf
Chapter 3 Spatial Domain Image Processing.pdf
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
gpt5_lecture_notes_comprehensive_20250812015547.pdf
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
MYSQL Presentation for SQL database connectivity
Encapsulation_ Review paper, used for researhc scholars
sap open course for s4hana steps from ECC to s4
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Network Security Unit 5.pdf for BCA BBA.
Per capita expenditure prediction using model stacking based on satellite ima...
cuic standard and advanced reporting.pdf
Approach and Philosophy of On baking technology
Teaching material agriculture food technology
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Review of recent advances in non-invasive hemoglobin estimation
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Empathic Computing: Creating Shared Understanding
The Rise and Fall of 3GPP – Time for a Sabbatical?

Closure Compiler vs YUICompressor