SlideShare uma empresa Scribd logo
1 de 9
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

Mais conteúdo relacionado

Mais procurados

Npm and bower
Npm and bowerNpm and bower
Npm and bowerJoan Yin
 
Apache Mesos Distributed Computing Talk
Apache Mesos Distributed Computing Talk Apache Mesos Distributed Computing Talk
Apache Mesos Distributed Computing Talk brandongulla
 
Explore the Cosmos (DB) with .NET Core 2.0
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
 
Scaling woo commerce-v2-pagely
Scaling woo commerce-v2-pagelyScaling woo commerce-v2-pagely
Scaling woo commerce-v2-pagelyJoshua Eichorn
 
Async ... Await – concurrency in java script
Async ... Await – concurrency in java scriptAsync ... Await – concurrency in java script
Async ... Await – concurrency in java scriptAthman Gude
 
WooCommerce System Status
WooCommerce System StatusWooCommerce System Status
WooCommerce System StatusRodolfo Melogli
 
GDI WordPress 1 January 2012
GDI WordPress 1 January 2012GDI WordPress 1 January 2012
GDI WordPress 1 January 2012pamselle
 
JSinSa 2015 - Progressive Saving Using LocalStorage
JSinSa 2015 - Progressive Saving Using LocalStorageJSinSa 2015 - Progressive Saving Using LocalStorage
JSinSa 2015 - Progressive Saving Using LocalStorageDaphneCalitz
 
Node.js rulz! JavaScript takes over the full Stack
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 StackAdron Hall
 
Introduction to NodeJS
Introduction to NodeJSIntroduction to NodeJS
Introduction to NodeJSZahid Mahir
 
Virtualizing MongoDB: Cloud, EC2, OpenStack, VMs...or Dedicated?
Virtualizing MongoDB: Cloud, EC2, OpenStack, VMs...or Dedicated?Virtualizing MongoDB: Cloud, EC2, OpenStack, VMs...or Dedicated?
Virtualizing MongoDB: Cloud, EC2, OpenStack, VMs...or Dedicated?MongoDB
 
Web assembly: a brief overview
Web assembly: a brief overviewWeb assembly: a brief overview
Web assembly: a brief overviewPavlo Iatsiuk
 
NodeSummit - MEAN Stack
NodeSummit - MEAN StackNodeSummit - MEAN Stack
NodeSummit - MEAN StackValeri Karpov
 
Use all the buzzwords
Use all the buzzwordsUse all the buzzwords
Use all the buzzwordsJared Faris
 
NodeJS and MEAN stack - II SorocabaJS
NodeJS and MEAN stack - II SorocabaJSNodeJS and MEAN stack - II SorocabaJS
NodeJS and MEAN stack - II SorocabaJSVitor Casadei
 

Mais procurados (20)

Npm and bower
Npm and bowerNpm and bower
Npm and bower
 
Apache Mesos Distributed Computing Talk
Apache Mesos Distributed Computing Talk Apache Mesos Distributed Computing Talk
Apache Mesos Distributed Computing Talk
 
Explore the Cosmos (DB) with .NET Core 2.0
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
 
WebSockets and Java
WebSockets and JavaWebSockets and Java
WebSockets and Java
 
Scaling woo commerce-v2-pagely
Scaling woo commerce-v2-pagelyScaling woo commerce-v2-pagely
Scaling woo commerce-v2-pagely
 
Async ... Await – concurrency in java script
Async ... Await – concurrency in java scriptAsync ... Await – concurrency in java script
Async ... Await – concurrency in java script
 
Rubyhosting
RubyhostingRubyhosting
Rubyhosting
 
WooCommerce System Status
WooCommerce System StatusWooCommerce System Status
WooCommerce System Status
 
GDI WordPress 1 January 2012
GDI WordPress 1 January 2012GDI WordPress 1 January 2012
GDI WordPress 1 January 2012
 
JSinSa 2015 - Progressive Saving Using LocalStorage
JSinSa 2015 - Progressive Saving Using LocalStorageJSinSa 2015 - Progressive Saving Using LocalStorage
JSinSa 2015 - Progressive Saving Using LocalStorage
 
Node.js rulz! JavaScript takes over the full Stack
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
 
Introduction to NodeJS
Introduction to NodeJSIntroduction to NodeJS
Introduction to NodeJS
 
Virtualizing MongoDB: Cloud, EC2, OpenStack, VMs...or Dedicated?
Virtualizing MongoDB: Cloud, EC2, OpenStack, VMs...or Dedicated?Virtualizing MongoDB: Cloud, EC2, OpenStack, VMs...or Dedicated?
Virtualizing MongoDB: Cloud, EC2, OpenStack, VMs...or Dedicated?
 
Web assembly: a brief overview
Web assembly: a brief overviewWeb assembly: a brief overview
Web assembly: a brief overview
 
Ruby course-1-preview
Ruby course-1-previewRuby course-1-preview
Ruby course-1-preview
 
NodeSummit - MEAN Stack
NodeSummit - MEAN StackNodeSummit - MEAN Stack
NodeSummit - MEAN Stack
 
Hello npm
Hello npmHello npm
Hello npm
 
Use all the buzzwords
Use all the buzzwordsUse all the buzzwords
Use all the buzzwords
 
NodeJS and MEAN stack - II SorocabaJS
NodeJS and MEAN stack - II SorocabaJSNodeJS and MEAN stack - II SorocabaJS
NodeJS and MEAN stack - II SorocabaJS
 
Servicestack
ServicestackServicestack
Servicestack
 

Semelhante a Extreme Javascript Minification

Golang @ Tokopedia
Golang @ TokopediaGolang @ Tokopedia
Golang @ TokopediaQasim Zaidi
 
Modules in Java? Finally! (OpenJDK 9 Jigsaw, JSR376)
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
 
Tech Headline - JavaScript Performance
Tech Headline - JavaScript PerformanceTech Headline - JavaScript Performance
Tech Headline - JavaScript PerformanceRodrigo Castilho
 
Introduction to Grails 2013
Introduction to Grails 2013Introduction to Grails 2013
Introduction to Grails 2013Gavin Hogan
 
Clojurescript slides
Clojurescript slidesClojurescript slides
Clojurescript slideselliando dias
 
Gearman: A Job Server made for Scale
Gearman: A Job Server made for ScaleGearman: A Job Server made for Scale
Gearman: A Job Server made for ScaleMike Willbanks
 
Scaling with Symfony - PHP UK
Scaling with Symfony - PHP UKScaling with Symfony - PHP UK
Scaling with Symfony - PHP UKRicard Clau
 
High performance json- postgre sql vs. mongodb
High performance json- postgre sql vs. mongodbHigh performance json- postgre sql vs. mongodb
High performance json- postgre sql vs. mongodbWei Shan Ang
 
Slices Of Performance in Java - Oleksandr Bodnar
Slices Of Performance in Java - Oleksandr BodnarSlices Of Performance in Java - Oleksandr Bodnar
Slices Of Performance in Java - Oleksandr BodnarGlobalLogic Ukraine
 
Introduction to go lang
Introduction to go langIntroduction to go lang
Introduction to go langAmal Mohan N
 
Ceph Performance: Projects Leading up to Jewel
Ceph Performance: Projects Leading up to JewelCeph Performance: Projects Leading up to Jewel
Ceph Performance: Projects Leading up to JewelColleen Corrice
 
Ceph Performance: Projects Leading Up to Jewel
Ceph Performance: Projects Leading Up to JewelCeph Performance: Projects Leading Up to Jewel
Ceph Performance: Projects Leading Up to JewelRed_Hat_Storage
 
Running JVM in Docker
Running JVM in DockerRunning JVM in Docker
Running JVM in DockerUri Savelchev
 
Leveraging MongoDB: An Introductory Case Study
Leveraging MongoDB: An Introductory Case StudyLeveraging MongoDB: An Introductory Case Study
Leveraging MongoDB: An Introductory Case StudySean Laurent
 
GoLang - Why It Matters
GoLang -  Why It MattersGoLang -  Why It Matters
GoLang - Why It Mattersrahul
 
Make JavaScript Lean, Mean, and Clean
Make JavaScript Lean, Mean, and CleanMake JavaScript Lean, Mean, and Clean
Make JavaScript Lean, Mean, and CleanBlue Raster
 

Semelhante a Extreme Javascript Minification (20)

Golang @ Tokopedia
Golang @ TokopediaGolang @ Tokopedia
Golang @ Tokopedia
 
Pulsar
PulsarPulsar
Pulsar
 
Gulp js
Gulp jsGulp js
Gulp js
 
Modules in Java? Finally! (OpenJDK 9 Jigsaw, JSR376)
Modules in Java? Finally! (OpenJDK 9 Jigsaw, JSR376)Modules in Java? Finally! (OpenJDK 9 Jigsaw, JSR376)
Modules in Java? Finally! (OpenJDK 9 Jigsaw, JSR376)
 
Go fundamentals
Go fundamentalsGo fundamentals
Go fundamentals
 
Tech Headline - JavaScript Performance
Tech Headline - JavaScript PerformanceTech Headline - JavaScript Performance
Tech Headline - JavaScript Performance
 
Web Optimisation
Web OptimisationWeb Optimisation
Web Optimisation
 
Introduction to Grails 2013
Introduction to Grails 2013Introduction to Grails 2013
Introduction to Grails 2013
 
Clojurescript slides
Clojurescript slidesClojurescript slides
Clojurescript slides
 
Gearman: A Job Server made for Scale
Gearman: A Job Server made for ScaleGearman: A Job Server made for Scale
Gearman: A Job Server made for Scale
 
Scaling with Symfony - PHP UK
Scaling with Symfony - PHP UKScaling with Symfony - PHP UK
Scaling with Symfony - PHP UK
 
High performance json- postgre sql vs. mongodb
High performance json- postgre sql vs. mongodbHigh performance json- postgre sql vs. mongodb
High performance json- postgre sql vs. mongodb
 
Slices Of Performance in Java - Oleksandr Bodnar
Slices Of Performance in Java - Oleksandr BodnarSlices Of Performance in Java - Oleksandr Bodnar
Slices Of Performance in Java - Oleksandr Bodnar
 
Introduction to go lang
Introduction to go langIntroduction to go lang
Introduction to go lang
 
Ceph Performance: Projects Leading up to Jewel
Ceph Performance: Projects Leading up to JewelCeph Performance: Projects Leading up to Jewel
Ceph Performance: Projects Leading up to Jewel
 
Ceph Performance: Projects Leading Up to Jewel
Ceph Performance: Projects Leading Up to JewelCeph Performance: Projects Leading Up to Jewel
Ceph Performance: Projects Leading Up to Jewel
 
Running JVM in Docker
Running JVM in DockerRunning JVM in Docker
Running JVM in Docker
 
Leveraging MongoDB: An Introductory Case Study
Leveraging MongoDB: An Introductory Case StudyLeveraging MongoDB: An Introductory Case Study
Leveraging MongoDB: An Introductory Case Study
 
GoLang - Why It Matters
GoLang -  Why It MattersGoLang -  Why It Matters
GoLang - Why It Matters
 
Make JavaScript Lean, Mean, and Clean
Make JavaScript Lean, Mean, and CleanMake JavaScript Lean, Mean, and Clean
Make JavaScript Lean, Mean, and Clean
 

Último

My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 

Último (20)

My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 

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