SlideShare a Scribd company logo
1 of 72
Download to read offline
Production optimization with

React and Webpack
@k88hudson
Firefox Engineering, Mozilla
🏎
Why React?
Abstracts away the DOM
Works on servers,
native apps, …Firefox?!?
It’s fast*
Helpful errors
Deterministic
component
rendering
Lifecycle
Testable
Why Webpack?
node_modules
file system
single bundle
for client-side
applications
Why optimization?
ERROR!
ERROR!
Users have high standards for
performance
Good optimization is not just making
everything faster, smaller and more
fault tolerant…
…it’s about being aware of your
options and making the right
compromises.
Everyone has Opinions™
Laws of benevolent optimization
Laws of benevolent optimization
1. Don’t optimize prematurely
2. Know your options
3. Instrument your sh*t
4. Set benchmarks that make sense for
your actual users
1. Don’t optimize prematurely
Before you optimize…
• Know what you’re building, address the UX/
product risk first
• Are your engineers on the same page as
your designers/product? Do you share a
common goal?
• Finish a few rounds of internal testing
• Have a good idea of who your users are
You might be ready to optimize if…
• You’re about to ship a product to market,
particularly on devices or in conditions that are
different from your development environment
• You’ve already shipped an MVP and are seeing
latency/perf/errors bog you down
• You’ve already shipped a product and have no
idea if it’s performing well but you feel like you
should probably figure that out
2. Know your options
Where can we optimize?
Development Build time
RuntimeAnalysis
Webpack—optimizing at
Build time
Development
Optimizing at build time
Transform code (for size, compatibility)
Manage configuration
Remove unused, non-essential code
Re-structure files/output
main.js
main.bundle.js
Typical Webpack set-up
Using custom loaders
Compiling ES2015 and JSX
<Foo bar />
React.createElement(Foo, { bar: true });
How big is the bundle?
Without webpack
react.js 628K
react-dom.js 4.0k
With webpack
main.js 648K
Webpack’s built-in production
optimization plugins
webpack -p
Webpack’s built-in production
optimization plugins
• optimize-minimize (UglifyJS)
• optimize-occurrence-order
• optimize-dedupe
With webpack -p
main.js 172K (-476k)
Another option—
Using the production build directly
With resolve/externals
main.js 136K (-512)
Use a production build of React
process.env.NODE_ENV
Use a production build of React
How DefinePlugin works
Using DefinePlugin for dev-only
dependencies
my-dev-logger will not be included in the bundle.
With webpack -p
NODE_ENV=production
main.js 128K (-520k)
This is stuff you should definitely be doing.
3. Instrument your sh*t
webpack --json
webpack-bundle-size-analyzer
React—optimizing at Runtime
First-load latency
First-load latency
First-load latency
General optimizations
If we render with JS…
loading…
Server-side rendering with react
Precompile the initial state
Instrumenting performance
Instrumenting performance
Time to first React render
Time to first React render

with content
Total render time
What if we’re having

rendering issues?
Reasons this might be a problem
• You are manipulating or reading the DOM directly
• You are handling very large arrays of complex
elements
• Your business logic contains computationally
expensive functions
• You are rendering very complex DOM elements (such
as SVG visualizations)
Manipulating/reading the DOM
Using keys correctly
Using keys correctly
Using keys correctly
shouldComponentUpdate
shouldComponentUpdate
Use React Perf tools
require(“react-addons-perf“);
Perf.printInclusive
Perf.printExclusive
Perf.printWasted
Perf.printOperations()
Laws of benevolent optimization
1. Don’t optimize prematurely
2. Know your options
3. Instrument your sh*t
4. Set benchmarks that make sense for
your actual users
What should you benchmark?
• File size
• Time to first load
• Time to render
What is acceptable depends on who your
users are what they’re likely to expect
The difference between 

over-engineering and good engineering
is making the right compromises
Thanks!
Tweet at me @k88hudson
😎

More Related Content

What's hot

What's hot (20)

Improving build solutions dependency management with webpack
Improving build solutions  dependency management with webpackImproving build solutions  dependency management with webpack
Improving build solutions dependency management with webpack
 
Lecture: Webpack 4
Lecture: Webpack 4Lecture: Webpack 4
Lecture: Webpack 4
 
Webpack: from 0 to 2
Webpack: from 0 to 2Webpack: from 0 to 2
Webpack: from 0 to 2
 
An Intro into webpack
An Intro into webpackAn Intro into webpack
An Intro into webpack
 
Webpack Introduction
Webpack IntroductionWebpack Introduction
Webpack Introduction
 
Webpack
WebpackWebpack
Webpack
 
Introduction of webpack 4
Introduction of webpack 4Introduction of webpack 4
Introduction of webpack 4
 
Webpack
Webpack Webpack
Webpack
 
Webpack DevTalk
Webpack DevTalkWebpack DevTalk
Webpack DevTalk
 
Webpack: your final module bundler
Webpack: your final module bundlerWebpack: your final module bundler
Webpack: your final module bundler
 
002. Working with Webpack
002. Working with Webpack002. Working with Webpack
002. Working with Webpack
 
Automate All the Things with Grunt
Automate All the Things with GruntAutomate All the Things with Grunt
Automate All the Things with Grunt
 
WordPress development checklist
WordPress development checklistWordPress development checklist
WordPress development checklist
 
Webpack Tutorial, Uppsala JS
Webpack Tutorial, Uppsala JSWebpack Tutorial, Uppsala JS
Webpack Tutorial, Uppsala JS
 
Hey webpack
Hey webpackHey webpack
Hey webpack
 
ReactJS Workflows
ReactJS WorkflowsReactJS Workflows
ReactJS Workflows
 
Bower & Grunt - A practical workflow
Bower & Grunt - A practical workflowBower & Grunt - A practical workflow
Bower & Grunt - A practical workflow
 
006. React - Redux framework
006. React - Redux framework006. React - Redux framework
006. React - Redux framework
 
Grunt and Bower
Grunt and BowerGrunt and Bower
Grunt and Bower
 
005. a React project structure
005. a React project structure005. a React project structure
005. a React project structure
 

Viewers also liked

Stappenplan blogger
Stappenplan bloggerStappenplan blogger
Stappenplan blogger
jufleonie
 
Spark and MongoDB
Spark and MongoDBSpark and MongoDB
Spark and MongoDB
Norberto Leite
 
Impacto de las tecnologías en la educación
Impacto de las tecnologías en la educaciónImpacto de las tecnologías en la educación
Impacto de las tecnologías en la educación
Salgado mtz
 

Viewers also liked (15)

Ed Batista, The Art of Self-Coaching @StanfordBiz, Class 6: Vulnerability
Ed Batista, The Art of Self-Coaching @StanfordBiz, Class 6: VulnerabilityEd Batista, The Art of Self-Coaching @StanfordBiz, Class 6: Vulnerability
Ed Batista, The Art of Self-Coaching @StanfordBiz, Class 6: Vulnerability
 
Webpack & React Performance in 16+ Steps
Webpack & React Performance in 16+ StepsWebpack & React Performance in 16+ Steps
Webpack & React Performance in 16+ Steps
 
Finally, Professional Frontend Dev with ReactJS, WebPack & Symfony (Symfony C...
Finally, Professional Frontend Dev with ReactJS, WebPack & Symfony (Symfony C...Finally, Professional Frontend Dev with ReactJS, WebPack & Symfony (Symfony C...
Finally, Professional Frontend Dev with ReactJS, WebPack & Symfony (Symfony C...
 
Sketching Web APIs
Sketching Web APIsSketching Web APIs
Sketching Web APIs
 
Stappenplan blogger
Stappenplan bloggerStappenplan blogger
Stappenplan blogger
 
Progressive web apps with polymer
Progressive web apps with polymerProgressive web apps with polymer
Progressive web apps with polymer
 
Keeping the frontend under control with Symfony and Webpack
Keeping the frontend under control with Symfony and WebpackKeeping the frontend under control with Symfony and Webpack
Keeping the frontend under control with Symfony and Webpack
 
Guard Authentication: Powerful, Beautiful Security
Guard Authentication: Powerful, Beautiful SecurityGuard Authentication: Powerful, Beautiful Security
Guard Authentication: Powerful, Beautiful Security
 
Progressive Web Apps [pt_BR]
Progressive Web Apps [pt_BR]Progressive Web Apps [pt_BR]
Progressive Web Apps [pt_BR]
 
EyeEM
EyeEMEyeEM
EyeEM
 
Spark and MongoDB
Spark and MongoDBSpark and MongoDB
Spark and MongoDB
 
Impacto de las tecnologías en la educación
Impacto de las tecnologías en la educaciónImpacto de las tecnologías en la educación
Impacto de las tecnologías en la educación
 
Effective Communications - Fundamentals of Public Relations
Effective Communications - Fundamentals of Public RelationsEffective Communications - Fundamentals of Public Relations
Effective Communications - Fundamentals of Public Relations
 
TEDx video - http://bit.ly/TEDxp - Persuasive Cities for Sustainable Wellbein...
TEDx video - http://bit.ly/TEDxp - Persuasive Cities for Sustainable Wellbein...TEDx video - http://bit.ly/TEDxp - Persuasive Cities for Sustainable Wellbein...
TEDx video - http://bit.ly/TEDxp - Persuasive Cities for Sustainable Wellbein...
 
Cloud Computing Clarity
Cloud Computing ClarityCloud Computing Clarity
Cloud Computing Clarity
 

Similar to Production optimization with React and Webpack

We4IT lcty 2013 - infra-man - whats new in ibm domino application development
We4IT lcty 2013 - infra-man - whats new in ibm domino application developmentWe4IT lcty 2013 - infra-man - whats new in ibm domino application development
We4IT lcty 2013 - infra-man - whats new in ibm domino application development
We4IT Group
 
Front-End Modernization for Mortals
Front-End Modernization for MortalsFront-End Modernization for Mortals
Front-End Modernization for Mortals
cgack
 

Similar to Production optimization with React and Webpack (20)

Angular + JHipster - JHipster Conf
Angular + JHipster - JHipster ConfAngular + JHipster - JHipster Conf
Angular + JHipster - JHipster Conf
 
Orlando DNN Usergroup Pres 12/06/11
Orlando DNN Usergroup Pres 12/06/11Orlando DNN Usergroup Pres 12/06/11
Orlando DNN Usergroup Pres 12/06/11
 
(ATS3-DEV08) Team Development with Accelrys Enterprise Platform
(ATS3-DEV08) Team Development with Accelrys Enterprise Platform(ATS3-DEV08) Team Development with Accelrys Enterprise Platform
(ATS3-DEV08) Team Development with Accelrys Enterprise Platform
 
2019 StartIT - Boosting your performance with Blackfire
2019 StartIT - Boosting your performance with Blackfire2019 StartIT - Boosting your performance with Blackfire
2019 StartIT - Boosting your performance with Blackfire
 
We4IT lcty 2013 - infra-man - whats new in ibm domino application development
We4IT lcty 2013 - infra-man - whats new in ibm domino application developmentWe4IT lcty 2013 - infra-man - whats new in ibm domino application development
We4IT lcty 2013 - infra-man - whats new in ibm domino application development
 
ICONUK 2015 - Gradle Up!
ICONUK 2015 - Gradle Up!ICONUK 2015 - Gradle Up!
ICONUK 2015 - Gradle Up!
 
Front-End Modernization for Mortals
Front-End Modernization for MortalsFront-End Modernization for Mortals
Front-End Modernization for Mortals
 
Front end-modernization
Front end-modernizationFront end-modernization
Front end-modernization
 
Front end-modernization
Front end-modernizationFront end-modernization
Front end-modernization
 
JS digest. Decemebr 2017
JS digest. Decemebr 2017JS digest. Decemebr 2017
JS digest. Decemebr 2017
 
Installing Webpack with React JS from Scratch.pdf
Installing Webpack with React JS from Scratch.pdfInstalling Webpack with React JS from Scratch.pdf
Installing Webpack with React JS from Scratch.pdf
 
Create ReactJS Component & publish as npm package
Create ReactJS Component & publish as npm packageCreate ReactJS Component & publish as npm package
Create ReactJS Component & publish as npm package
 
Performant Django - Ara Anjargolian
Performant Django - Ara AnjargolianPerformant Django - Ara Anjargolian
Performant Django - Ara Anjargolian
 
Profiling and Tuning a Web Application - The Dirty Details
Profiling and Tuning a Web Application - The Dirty DetailsProfiling and Tuning a Web Application - The Dirty Details
Profiling and Tuning a Web Application - The Dirty Details
 
Creating a reasonable project boilerplate
Creating a reasonable project boilerplateCreating a reasonable project boilerplate
Creating a reasonable project boilerplate
 
Opticon18: Developer Night
Opticon18: Developer NightOpticon18: Developer Night
Opticon18: Developer Night
 
The WordPress Performance Team
The WordPress Performance TeamThe WordPress Performance Team
The WordPress Performance Team
 
Webpack essentails - feb 19, 2020
Webpack essentails - feb 19, 2020Webpack essentails - feb 19, 2020
Webpack essentails - feb 19, 2020
 
SOA Knowledge Kit, Developer Productivity and Performance Comparison Analysis
SOA Knowledge Kit, Developer Productivity  and Performance Comparison AnalysisSOA Knowledge Kit, Developer Productivity  and Performance Comparison Analysis
SOA Knowledge Kit, Developer Productivity and Performance Comparison Analysis
 
Continuous integration / continuous delivery
Continuous integration / continuous deliveryContinuous integration / continuous delivery
Continuous integration / continuous delivery
 

Recently uploaded

Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptxHarnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
FIDO Alliance
 
CORS (Kitworks Team Study 양다윗 발표자료 240510)
CORS (Kitworks Team Study 양다윗 발표자료 240510)CORS (Kitworks Team Study 양다윗 발표자료 240510)
CORS (Kitworks Team Study 양다윗 발표자료 240510)
Wonjun Hwang
 
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc
 

Recently uploaded (20)

Cyber Insurance - RalphGilot - Embry-Riddle Aeronautical University.pptx
Cyber Insurance - RalphGilot - Embry-Riddle Aeronautical University.pptxCyber Insurance - RalphGilot - Embry-Riddle Aeronautical University.pptx
Cyber Insurance - RalphGilot - Embry-Riddle Aeronautical University.pptx
 
Frisco Automating Purchase Orders with MuleSoft IDP- May 10th, 2024.pptx.pdf
Frisco Automating Purchase Orders with MuleSoft IDP- May 10th, 2024.pptx.pdfFrisco Automating Purchase Orders with MuleSoft IDP- May 10th, 2024.pptx.pdf
Frisco Automating Purchase Orders with MuleSoft IDP- May 10th, 2024.pptx.pdf
 
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptxHarnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
 
CORS (Kitworks Team Study 양다윗 발표자료 240510)
CORS (Kitworks Team Study 양다윗 발표자료 240510)CORS (Kitworks Team Study 양다윗 발표자료 240510)
CORS (Kitworks Team Study 양다윗 발표자료 240510)
 
The Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and InsightThe Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and Insight
 
UiPath manufacturing technology benefits and AI overview
UiPath manufacturing technology benefits and AI overviewUiPath manufacturing technology benefits and AI overview
UiPath manufacturing technology benefits and AI overview
 
Easier, Faster, and More Powerful – Notes Document Properties Reimagined
Easier, Faster, and More Powerful – Notes Document Properties ReimaginedEasier, Faster, and More Powerful – Notes Document Properties Reimagined
Easier, Faster, and More Powerful – Notes Document Properties Reimagined
 
How to Check GPS Location with a Live Tracker in Pakistan
How to Check GPS Location with a Live Tracker in PakistanHow to Check GPS Location with a Live Tracker in Pakistan
How to Check GPS Location with a Live Tracker in Pakistan
 
Top 10 CodeIgniter Development Companies
Top 10 CodeIgniter Development CompaniesTop 10 CodeIgniter Development Companies
Top 10 CodeIgniter Development Companies
 
WebRTC and SIP not just audio and video @ OpenSIPS 2024
WebRTC and SIP not just audio and video @ OpenSIPS 2024WebRTC and SIP not just audio and video @ OpenSIPS 2024
WebRTC and SIP not just audio and video @ OpenSIPS 2024
 
Continuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
Continuing Bonds Through AI: A Hermeneutic Reflection on ThanabotsContinuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
Continuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
 
Event-Driven Architecture Masterclass: Challenges in Stream Processing
Event-Driven Architecture Masterclass: Challenges in Stream ProcessingEvent-Driven Architecture Masterclass: Challenges in Stream Processing
Event-Driven Architecture Masterclass: Challenges in Stream Processing
 
ERP Contender Series: Acumatica vs. Sage Intacct
ERP Contender Series: Acumatica vs. Sage IntacctERP Contender Series: Acumatica vs. Sage Intacct
ERP Contender Series: Acumatica vs. Sage Intacct
 
Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMIntroduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDM
 
Overview of Hyperledger Foundation
Overview of Hyperledger FoundationOverview of Hyperledger Foundation
Overview of Hyperledger Foundation
 
Generative AI Use Cases and Applications.pdf
Generative AI Use Cases and Applications.pdfGenerative AI Use Cases and Applications.pdf
Generative AI Use Cases and Applications.pdf
 
Oauth 2.0 Introduction and Flows with MuleSoft
Oauth 2.0 Introduction and Flows with MuleSoftOauth 2.0 Introduction and Flows with MuleSoft
Oauth 2.0 Introduction and Flows with MuleSoft
 
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
 

Production optimization with React and Webpack