Extreme Javascript Minification

David Goemans
David GoemansProject Manager at Creative Clicks
Extreme Javascript Minification 
Compression experiments for JS13k 
by David Goemans 
BoosterMedia 2014
• For JS13k, your delivered package needs to be 13kb or less 
• It can be compressed but as a standard zip format 
• This gives you about 90kb for actual code 
• Many techniques available: 
• Uglify2JS 
• YUI 
• Closure 
• JS Crush & Packer 
• Zip Formats are restrictive 
• Renaming tricks ( Globals ) 
What?
• Very good for day-to-day compress 
Uglify2JS 
• Node/Grunt module makes for super easy integration 
• Works out of the box, virtually never requires code changes 
• Compresses very well, but not well enough
• With advanced compression, performs better than Uglify 
• Minimal code changes required to make it compress well 
• Compression is pretty good, but... 
YUI
• Great compression with advanced compilation 
• Requires code changes, especially related to global variables 
• Some APIs not recognized by the compiler, such as PointerLock 
• Best compression for zipping 
Closure 
~75kb code ~26kb code
JSCrush & Packer 
• These are amazing pieces of technology. 
• Crazy compression for javascript, much smaller .js files than the other options 
• For best results, first run through Closure or Uglify with simple optimizations 
• Since they're already so well compressed, they don't zip very well 
• Not that useful for JS13k, and normal use, but great for JS1k!
• Zip has a few algorithms you can use, but only deflate is widely supported 
• Deflate is based on Huffman trees, which works by detecting patterns 
• Lots of the same text close together compresses well 
• This is why JSCrush/Packer doesn't zip very well! 
• Each file generates some overhead 
• 
• Less files with shorter names is best 
Zip
Extra tricks 
• Remember, reserved words can't be minified. 
• Re-define common long reserved names and attach to a global object 
Instead of: 
gl.TEXTURE_MIN_FILTER 
Global.js: 
var $; 
$.minFilterVar = 'TEXTURE_MIN_FILTER'; 
everywhere else: 
gl[$.minFilterVar] 
• Seems longer at first, but compresses really well!
David Goemans 
Lead developer @ BoosterMedia Game Studio 
david.goemans@boostermedia.com 
@dgoemans 
About me 
Links: 
JS13k Project code: 
https://github.com/dgoemans/shipwrecked 
Extra info on zip compression: 
https://gist.github.com/subzey/b18c482922cd17693d65
1 of 9

Recommended

$PENK->{'YAPC::Tiny'}; by
$PENK->{'YAPC::Tiny'};$PENK->{'YAPC::Tiny'};
$PENK->{'YAPC::Tiny'};Ping-Hsun Chen
433 views27 slides
Wordpress -> Middleman: Lesson learned in the 2-years since migrating by
Wordpress -> Middleman: Lesson learned in the 2-years since migratingWordpress -> Middleman: Lesson learned in the 2-years since migrating
Wordpress -> Middleman: Lesson learned in the 2-years since migratingJames Stone
1.3K views14 slides
Web Development Fundamentals by
Web Development FundamentalsWeb Development Fundamentals
Web Development FundamentalsAnoop Thomas Mathew
1.8K views13 slides
What The Web! by
What The Web!What The Web!
What The Web!Anoop Thomas Mathew
1.1K views12 slides
extended slow parts, HTML5 meets WPO by
extended slow parts, HTML5 meets WPOextended slow parts, HTML5 meets WPO
extended slow parts, HTML5 meets WPOFrancesco Fullone
713 views22 slides
Lessons learned from Node.js - Callbacks / Promises by
Lessons learned from Node.js - Callbacks / PromisesLessons learned from Node.js - Callbacks / Promises
Lessons learned from Node.js - Callbacks / PromisesJason K Yau
987 views37 slides

More Related Content

What's hot

Npm and bower by
Npm and bowerNpm and bower
Npm and bowerJoan Yin
444 views3 slides
Apache Mesos Distributed Computing Talk by
Apache Mesos Distributed Computing Talk Apache Mesos Distributed Computing Talk
Apache Mesos Distributed Computing Talk brandongulla
293 views26 slides
Explore the Cosmos (DB) with .NET Core 2.0 by
Explore the Cosmos (DB) with .NET Core 2.0Explore the Cosmos (DB) with .NET Core 2.0
Explore the Cosmos (DB) with .NET Core 2.0Jeremy Likness
4.1K views19 slides
WebSockets and Java by
WebSockets and JavaWebSockets and Java
WebSockets and JavaBozhidar Bozhanov
3.3K views12 slides
Scaling woo commerce-v2-pagely by
Scaling woo commerce-v2-pagelyScaling woo commerce-v2-pagely
Scaling woo commerce-v2-pagelyJoshua Eichorn
1.9K views20 slides
Async ... Await – concurrency in java script by
Async ... Await – concurrency in java scriptAsync ... Await – concurrency in java script
Async ... Await – concurrency in java scriptAthman Gude
182 views37 slides

What's hot(20)

Npm and bower by Joan Yin
Npm and bowerNpm and bower
Npm and bower
Joan Yin444 views
Apache Mesos Distributed Computing Talk by brandongulla
Apache Mesos Distributed Computing Talk Apache Mesos Distributed Computing Talk
Apache Mesos Distributed Computing Talk
brandongulla293 views
Explore the Cosmos (DB) with .NET Core 2.0 by Jeremy Likness
Explore the Cosmos (DB) with .NET Core 2.0Explore the Cosmos (DB) with .NET Core 2.0
Explore the Cosmos (DB) with .NET Core 2.0
Jeremy Likness4.1K views
Scaling woo commerce-v2-pagely by Joshua Eichorn
Scaling woo commerce-v2-pagelyScaling woo commerce-v2-pagely
Scaling woo commerce-v2-pagely
Joshua Eichorn1.9K views
Async ... Await – concurrency in java script by Athman Gude
Async ... Await – concurrency in java scriptAsync ... Await – concurrency in java script
Async ... Await – concurrency in java script
Athman Gude182 views
GDI WordPress 1 January 2012 by pamselle
GDI WordPress 1 January 2012GDI WordPress 1 January 2012
GDI WordPress 1 January 2012
pamselle448 views
JSinSa 2015 - Progressive Saving Using LocalStorage by DaphneCalitz
JSinSa 2015 - Progressive Saving Using LocalStorageJSinSa 2015 - Progressive Saving Using LocalStorage
JSinSa 2015 - Progressive Saving Using LocalStorage
DaphneCalitz211 views
Node.js rulz! JavaScript takes over the full Stack by Adron Hall
Node.js rulz! JavaScript takes over the full StackNode.js rulz! JavaScript takes over the full Stack
Node.js rulz! JavaScript takes over the full Stack
Adron Hall1.1K views
Introduction to NodeJS by Zahid Mahir
Introduction to NodeJSIntroduction to NodeJS
Introduction to NodeJS
Zahid Mahir832 views
Virtualizing MongoDB: Cloud, EC2, OpenStack, VMs...or Dedicated? by MongoDB
Virtualizing MongoDB: Cloud, EC2, OpenStack, VMs...or Dedicated?Virtualizing MongoDB: Cloud, EC2, OpenStack, VMs...or Dedicated?
Virtualizing MongoDB: Cloud, EC2, OpenStack, VMs...or Dedicated?
MongoDB3.2K views
Web assembly: a brief overview by Pavlo Iatsiuk
Web assembly: a brief overviewWeb assembly: a brief overview
Web assembly: a brief overview
Pavlo Iatsiuk98 views
NodeSummit - MEAN Stack by Valeri Karpov
NodeSummit - MEAN StackNodeSummit - MEAN Stack
NodeSummit - MEAN Stack
Valeri Karpov4.1K views
Use all the buzzwords by Jared Faris
Use all the buzzwordsUse all the buzzwords
Use all the buzzwords
Jared Faris1.3K views
NodeJS and MEAN stack - II SorocabaJS by Vitor Casadei
NodeJS and MEAN stack - II SorocabaJSNodeJS and MEAN stack - II SorocabaJS
NodeJS and MEAN stack - II SorocabaJS
Vitor Casadei297 views

Similar to Extreme Javascript Minification

Golang @ Tokopedia by
Golang @ TokopediaGolang @ Tokopedia
Golang @ TokopediaQasim Zaidi
2.6K views41 slides
Pulsar by
PulsarPulsar
PulsarEugene Lazutkin
944 views41 slides
Gulp js by
Gulp jsGulp js
Gulp jsKen Gilbert
309 views18 slides
Modules in Java? Finally! (OpenJDK 9 Jigsaw, JSR376) by
Modules in Java? Finally! (OpenJDK 9 Jigsaw, JSR376)Modules in Java? Finally! (OpenJDK 9 Jigsaw, JSR376)
Modules in Java? Finally! (OpenJDK 9 Jigsaw, JSR376)Mihail Stoynov
10.5K views40 slides
Go fundamentals by
Go fundamentalsGo fundamentals
Go fundamentalsRon Barabash
29 views30 slides
Tech Headline - JavaScript Performance by
Tech Headline - JavaScript PerformanceTech Headline - JavaScript Performance
Tech Headline - JavaScript PerformanceRodrigo Castilho
909 views48 slides

Similar to Extreme Javascript Minification(20)

Golang @ Tokopedia by Qasim Zaidi
Golang @ TokopediaGolang @ Tokopedia
Golang @ Tokopedia
Qasim Zaidi2.6K views
Modules in Java? Finally! (OpenJDK 9 Jigsaw, JSR376) by Mihail Stoynov
Modules in Java? Finally! (OpenJDK 9 Jigsaw, JSR376)Modules in Java? Finally! (OpenJDK 9 Jigsaw, JSR376)
Modules in Java? Finally! (OpenJDK 9 Jigsaw, JSR376)
Mihail Stoynov10.5K views
Tech Headline - JavaScript Performance by Rodrigo Castilho
Tech Headline - JavaScript PerformanceTech Headline - JavaScript Performance
Tech Headline - JavaScript Performance
Rodrigo Castilho909 views
Introduction to Grails 2013 by Gavin Hogan
Introduction to Grails 2013Introduction to Grails 2013
Introduction to Grails 2013
Gavin Hogan1.2K views
Gearman: A Job Server made for Scale by Mike Willbanks
Gearman: A Job Server made for ScaleGearman: A Job Server made for Scale
Gearman: A Job Server made for Scale
Mike Willbanks9.1K views
Scaling with Symfony - PHP UK by Ricard Clau
Scaling with Symfony - PHP UKScaling with Symfony - PHP UK
Scaling with Symfony - PHP UK
Ricard Clau13K views
High performance json- postgre sql vs. mongodb by Wei Shan Ang
High performance json- postgre sql vs. mongodbHigh performance json- postgre sql vs. mongodb
High performance json- postgre sql vs. mongodb
Wei Shan Ang640 views
Slices Of Performance in Java - Oleksandr Bodnar by GlobalLogic Ukraine
Slices Of Performance in Java - Oleksandr BodnarSlices Of Performance in Java - Oleksandr Bodnar
Slices Of Performance in Java - Oleksandr Bodnar
Introduction to go lang by Amal Mohan N
Introduction to go langIntroduction to go lang
Introduction to go lang
Amal Mohan N567 views
Ceph Performance: Projects Leading Up to Jewel by Red_Hat_Storage
Ceph Performance: Projects Leading Up to JewelCeph Performance: Projects Leading Up to Jewel
Ceph Performance: Projects Leading Up to Jewel
Red_Hat_Storage4.2K views
Ceph Performance: Projects Leading up to Jewel by Colleen Corrice
Ceph Performance: Projects Leading up to JewelCeph Performance: Projects Leading up to Jewel
Ceph Performance: Projects Leading up to Jewel
Colleen Corrice189 views
Leveraging MongoDB: An Introductory Case Study by Sean Laurent
Leveraging MongoDB: An Introductory Case StudyLeveraging MongoDB: An Introductory Case Study
Leveraging MongoDB: An Introductory Case Study
Sean Laurent923 views
GoLang - Why It Matters by rahul
GoLang -  Why It MattersGoLang -  Why It Matters
GoLang - Why It Matters
rahul 135 views
Make JavaScript Lean, Mean, and Clean by Blue Raster
Make JavaScript Lean, Mean, and CleanMake JavaScript Lean, Mean, and Clean
Make JavaScript Lean, Mean, and Clean
Blue Raster348 views

Recently uploaded

Generative AI: Shifting the AI Landscape by
Generative AI: Shifting the AI LandscapeGenerative AI: Shifting the AI Landscape
Generative AI: Shifting the AI LandscapeDeakin University
53 views55 slides
Enabling DPU Hardware Accelerators in XCP-ng Cloud Platform Environment - And... by
Enabling DPU Hardware Accelerators in XCP-ng Cloud Platform Environment - And...Enabling DPU Hardware Accelerators in XCP-ng Cloud Platform Environment - And...
Enabling DPU Hardware Accelerators in XCP-ng Cloud Platform Environment - And...ShapeBlue
106 views12 slides
State of the Union - Rohit Yadav - Apache CloudStack by
State of the Union - Rohit Yadav - Apache CloudStackState of the Union - Rohit Yadav - Apache CloudStack
State of the Union - Rohit Yadav - Apache CloudStackShapeBlue
297 views53 slides
The Power of Heat Decarbonisation Plans in the Built Environment by
The Power of Heat Decarbonisation Plans in the Built EnvironmentThe Power of Heat Decarbonisation Plans in the Built Environment
The Power of Heat Decarbonisation Plans in the Built EnvironmentIES VE
79 views20 slides
Business Analyst Series 2023 - Week 4 Session 7 by
Business Analyst Series 2023 -  Week 4 Session 7Business Analyst Series 2023 -  Week 4 Session 7
Business Analyst Series 2023 - Week 4 Session 7DianaGray10
139 views31 slides
Centralized Logging Feature in CloudStack using ELK and Grafana - Kiran Chava... by
Centralized Logging Feature in CloudStack using ELK and Grafana - Kiran Chava...Centralized Logging Feature in CloudStack using ELK and Grafana - Kiran Chava...
Centralized Logging Feature in CloudStack using ELK and Grafana - Kiran Chava...ShapeBlue
145 views17 slides

Recently uploaded(20)

Enabling DPU Hardware Accelerators in XCP-ng Cloud Platform Environment - And... by ShapeBlue
Enabling DPU Hardware Accelerators in XCP-ng Cloud Platform Environment - And...Enabling DPU Hardware Accelerators in XCP-ng Cloud Platform Environment - And...
Enabling DPU Hardware Accelerators in XCP-ng Cloud Platform Environment - And...
ShapeBlue106 views
State of the Union - Rohit Yadav - Apache CloudStack by ShapeBlue
State of the Union - Rohit Yadav - Apache CloudStackState of the Union - Rohit Yadav - Apache CloudStack
State of the Union - Rohit Yadav - Apache CloudStack
ShapeBlue297 views
The Power of Heat Decarbonisation Plans in the Built Environment by IES VE
The Power of Heat Decarbonisation Plans in the Built EnvironmentThe Power of Heat Decarbonisation Plans in the Built Environment
The Power of Heat Decarbonisation Plans in the Built Environment
IES VE79 views
Business Analyst Series 2023 - Week 4 Session 7 by DianaGray10
Business Analyst Series 2023 -  Week 4 Session 7Business Analyst Series 2023 -  Week 4 Session 7
Business Analyst Series 2023 - Week 4 Session 7
DianaGray10139 views
Centralized Logging Feature in CloudStack using ELK and Grafana - Kiran Chava... by ShapeBlue
Centralized Logging Feature in CloudStack using ELK and Grafana - Kiran Chava...Centralized Logging Feature in CloudStack using ELK and Grafana - Kiran Chava...
Centralized Logging Feature in CloudStack using ELK and Grafana - Kiran Chava...
ShapeBlue145 views
Hypervisor Agnostic DRS in CloudStack - Brief overview & demo - Vishesh Jinda... by ShapeBlue
Hypervisor Agnostic DRS in CloudStack - Brief overview & demo - Vishesh Jinda...Hypervisor Agnostic DRS in CloudStack - Brief overview & demo - Vishesh Jinda...
Hypervisor Agnostic DRS in CloudStack - Brief overview & demo - Vishesh Jinda...
ShapeBlue161 views
NTGapps NTG LowCode Platform by Mustafa Kuğu
NTGapps NTG LowCode Platform NTGapps NTG LowCode Platform
NTGapps NTG LowCode Platform
Mustafa Kuğu423 views
GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N... by James Anderson
GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N...GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N...
GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N...
James Anderson160 views
2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlue by ShapeBlue
2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlue2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlue
2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlue
ShapeBlue147 views
Updates on the LINSTOR Driver for CloudStack - Rene Peinthor - LINBIT by ShapeBlue
Updates on the LINSTOR Driver for CloudStack - Rene Peinthor - LINBITUpdates on the LINSTOR Driver for CloudStack - Rene Peinthor - LINBIT
Updates on the LINSTOR Driver for CloudStack - Rene Peinthor - LINBIT
ShapeBlue206 views
Import Export Virtual Machine for KVM Hypervisor - Ayush Pandey - University ... by ShapeBlue
Import Export Virtual Machine for KVM Hypervisor - Ayush Pandey - University ...Import Export Virtual Machine for KVM Hypervisor - Ayush Pandey - University ...
Import Export Virtual Machine for KVM Hypervisor - Ayush Pandey - University ...
ShapeBlue119 views
CloudStack and GitOps at Enterprise Scale - Alex Dometrius, Rene Glover - AT&T by ShapeBlue
CloudStack and GitOps at Enterprise Scale - Alex Dometrius, Rene Glover - AT&TCloudStack and GitOps at Enterprise Scale - Alex Dometrius, Rene Glover - AT&T
CloudStack and GitOps at Enterprise Scale - Alex Dometrius, Rene Glover - AT&T
ShapeBlue152 views
Digital Personal Data Protection (DPDP) Practical Approach For CISOs by Priyanka Aash
Digital Personal Data Protection (DPDP) Practical Approach For CISOsDigital Personal Data Protection (DPDP) Practical Approach For CISOs
Digital Personal Data Protection (DPDP) Practical Approach For CISOs
Priyanka Aash158 views
Migrating VMware Infra to KVM Using CloudStack - Nicolas Vazquez - ShapeBlue by ShapeBlue
Migrating VMware Infra to KVM Using CloudStack - Nicolas Vazquez - ShapeBlueMigrating VMware Infra to KVM Using CloudStack - Nicolas Vazquez - ShapeBlue
Migrating VMware Infra to KVM Using CloudStack - Nicolas Vazquez - ShapeBlue
ShapeBlue218 views
CloudStack Managed User Data and Demo - Harikrishna Patnala - ShapeBlue by ShapeBlue
CloudStack Managed User Data and Demo - Harikrishna Patnala - ShapeBlueCloudStack Managed User Data and Demo - Harikrishna Patnala - ShapeBlue
CloudStack Managed User Data and Demo - Harikrishna Patnala - ShapeBlue
ShapeBlue135 views
Why and How CloudStack at weSystems - Stephan Bienek - weSystems by ShapeBlue
Why and How CloudStack at weSystems - Stephan Bienek - weSystemsWhy and How CloudStack at weSystems - Stephan Bienek - weSystems
Why and How CloudStack at weSystems - Stephan Bienek - weSystems
ShapeBlue238 views
Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P... by ShapeBlue
Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P...Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P...
Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P...
ShapeBlue194 views
Live Demo Showcase: Unveiling Dell PowerFlex’s IaaS Capabilities with Apache ... by ShapeBlue
Live Demo Showcase: Unveiling Dell PowerFlex’s IaaS Capabilities with Apache ...Live Demo Showcase: Unveiling Dell PowerFlex’s IaaS Capabilities with Apache ...
Live Demo Showcase: Unveiling Dell PowerFlex’s IaaS Capabilities with Apache ...
ShapeBlue126 views
Zero to Cloud Hero: Crafting a Private Cloud from Scratch with XCP-ng, Xen Or... by ShapeBlue
Zero to Cloud Hero: Crafting a Private Cloud from Scratch with XCP-ng, Xen Or...Zero to Cloud Hero: Crafting a Private Cloud from Scratch with XCP-ng, Xen Or...
Zero to Cloud Hero: Crafting a Private Cloud from Scratch with XCP-ng, Xen Or...
ShapeBlue198 views

Extreme Javascript Minification

  • 1. Extreme Javascript Minification Compression experiments for JS13k by David Goemans BoosterMedia 2014
  • 2. • For JS13k, your delivered package needs to be 13kb or less • It can be compressed but as a standard zip format • This gives you about 90kb for actual code • Many techniques available: • Uglify2JS • YUI • Closure • JS Crush & Packer • Zip Formats are restrictive • Renaming tricks ( Globals ) What?
  • 3. • Very good for day-to-day compress Uglify2JS • Node/Grunt module makes for super easy integration • Works out of the box, virtually never requires code changes • Compresses very well, but not well enough
  • 4. • With advanced compression, performs better than Uglify • Minimal code changes required to make it compress well • Compression is pretty good, but... YUI
  • 5. • Great compression with advanced compilation • Requires code changes, especially related to global variables • Some APIs not recognized by the compiler, such as PointerLock • Best compression for zipping Closure ~75kb code ~26kb code
  • 6. JSCrush & Packer • These are amazing pieces of technology. • Crazy compression for javascript, much smaller .js files than the other options • For best results, first run through Closure or Uglify with simple optimizations • Since they're already so well compressed, they don't zip very well • Not that useful for JS13k, and normal use, but great for JS1k!
  • 7. • Zip has a few algorithms you can use, but only deflate is widely supported • Deflate is based on Huffman trees, which works by detecting patterns • Lots of the same text close together compresses well • This is why JSCrush/Packer doesn't zip very well! • Each file generates some overhead • • Less files with shorter names is best Zip
  • 8. Extra tricks • Remember, reserved words can't be minified. • Re-define common long reserved names and attach to a global object Instead of: gl.TEXTURE_MIN_FILTER Global.js: var $; $.minFilterVar = 'TEXTURE_MIN_FILTER'; everywhere else: gl[$.minFilterVar] • Seems longer at first, but compresses really well!
  • 9. David Goemans Lead developer @ BoosterMedia Game Studio david.goemans@boostermedia.com @dgoemans About me Links: JS13k Project code: https://github.com/dgoemans/shipwrecked Extra info on zip compression: https://gist.github.com/subzey/b18c482922cd17693d65