SlideShare a Scribd company logo
1 of 65
W R I T I N G R E A C T F O R T H E
M O B I L E W E B
C A S E S T U D Y:
B R I A N H O LT
@ H O LT B T – B R I @ N H O . LT
InfoQ.com: News & Community Site
• 750,000 unique visitors/month
• Published in 4 languages (English, Chinese, Japanese and Brazilian
Portuguese)
• Post content from our QCon conferences
• News 15-20 / week
• Articles 3-4 / week
• Presentations (videos) 12-15 / week
• Interviews 2-3 / week
• Books 1 / month
Watch the video with slide
synchronization on InfoQ.com!
http://www.infoq.com/presentations/
react-reddit-mobile
Purpose of QCon
- to empower software development by facilitating the spread of
knowledge and innovation
Strategy
- practitioner-driven conference designed for YOU: influencers of
change and innovation in your teams
- speakers and topics driving the evolution and innovation
- connecting and catalyzing the influencers and innovators
Highlights
- attended by more than 12,000 delegates since 2007
- held in 9 cities worldwide
Presented at QCon San Francisco
www.qconsf.com
W H Y I S W R I T I N G R E A C T
D I F F E R E N T F O R T H E M O B I L E W E B ?
I T ’ S N O T.
F I N
B R I A N H O LT
@ H O LT B T
L O L J K
P E R F
P E R F M AT T E R S O N M O B I L E .
A L O T.
W R I T I N G P E R F O R M A N T R E A C T
B R I A N H O LT
@ H O LT B T
W E B P E R F O R M A N C E
B R I A N H O LT
@ H O LT B T
P E R F M AT T E R S
• Data speed
• Data cost
• Battery drain
• Bad UX
• Longer load time is LESS ****ING MONEY.
hey reddit
lol
mobile reddit’s
perf is bad
****
G E N E R A L P E R F T I P S
U S E I M A G E S S PA R I N G LY.
O P T I M I Z E T H E O N E S Y O U D O U S E .
C A C H E
C A C H E
• Cache images as long as possible.
• Consider separating scripts and styles that change frequently from scripts
and styles that remain the same.
• e.g. Separate your vendor code like Bootstrap from your app code.
• Use naming conventions to invalidate cache.
H T T P C A C H I N G I S N ’ T A S G R E AT A S Y O U T H I N K
• IE, Chrome, Safari and Firefox only keep ~200MB of cache on hand.
• Android keeps 80MB of cache.
• Mobile Safari has no HTTP cache.
D O N ’ T U S E A W E B F O N T.
T E L L Y O U R D E S I G N E R T O * * * * O F F I F H E / S H E
WA N T S T O .
I C O N F O N T S A R E * * * * T O O . T H E Y ’ R E B I G
A N D T H E Y ’ R E H A R D T O M A K E A C C E S S I B L E .
Y O U ’ R E S L O W I N G D O W N Y O U R W E B S I T E T O
M A K E I T L E S S A C C E S S I B L E .
G O O D J O B .
C R I T I C A L R E N D E R I N G PAT H
• This is a psychology game. You want the fastest perceived page load.
• Defer anything not critical to the first paint to after it.
• However, once you have had your first paint, starting loading everything as
fast as you can!
F I L E S I Z E
• Having just gone to China where data was real expensive to use, CUT
DOWN YOUR ****ING FILE SIZES.
• Only include polyfills (especially with Babel) you use.
• e.g. with lodash, only include methods you use.
• Dedupe your dependencies.
W E ' D L I K E T O I M A G I N E T H AT T H E WAY A W E B PA G E
L O A D S I S T H I S :
1. Browser opens connection to yoursite.com, does DNS/TCP/SSL setup.
2. Browser downloads the document (HTML).
3. As soon as the browser is done downloading the document, the browser
starts downloading all the document's sub resources at the same time.
4. Browser parses the document and fills in the necessary sub resources
once they've been downloaded.
source: nateberkopec.com/2015/11/05/page-weight-doesnt-matter.html
H E R E ' S W H AT A C T U A L LY H A P P E N S :
1. Browser opens connection to yoursite.com, does DNS/TCP/SSL setup.
2. Browser downloads the document (HTML).
3. Browser starts parsing the document. When the parser encounters a subresource, it opens a
connection and downloads it.
4. Parse the document? Nah man, I'm gonna wait for this script to download and execute. If the
subresource is an external script tag, the parser stops, waits until it the script has downloaded,
executes the entire script, and then moves on.
5. As soon as the parser stops and has to wait for an external script to download, it sends ahead
something called a preloader. The preloader may notice and begin downloading resources if it
understands how to (hint: a very popular Javascript pattern prevents this).
source: nateberkopec.com/2015/11/05/page-weight-doesnt-matter.html
W H AT T O D O
• Don't stop the parser.
• Get out of the browser preloader's way.
• Utilize HTTP caching - but not too much.
• Use the Resource Hint API.
source: nateberkopec.com/2015/11/05/page-weight-doesnt-matter.html
R E S O U R C E H I N T S
• preconnect – A neat little trick to let the browser know about things that it
couldn’t otherwise. A good example would be a script tag you’re going to
inject later.
• prefetch – Great for grabbing resources for the next page the user is going
to hit. If you’re in a funnel and you know where the user is going next,
prefect those resources.
• prerender – Grab and actually pretender an HTML resource. Great for
something like Google Instant Pages.
U S E A S Y N C A N D D E F E R AT T R I B U T E S O N Y O U R
S C R I P T TA G S
normal
async
defer
source: growingwiththeweb.com/2014/02/async-vs-defer-attributes.html
W H AT AT T R I B U T E W H E N
• Typically you want to use async where possible, then defer then no
attribute. Here are some general rules to follow:
• If the script is modular and does not rely on any scripts then use async.
• If the script relies upon or is relied upon by another script then use defer.
• If the script is small and is relied upon by an async script then use an inline
script with no attributes placed above the async scripts.
source: growingwiththeweb.com/2014/02/async-vs-defer-attributes.html
D E F E R G U A R A N T E E S O R D E R O F
E X E C U T I O N .
A S Y N C D O E S N O T.
I F Y O U R T R A C K I N G O R A N A LY T I C S A R E N O T
A S Y N C , Y O U M A K E K I T T Y S A D
A N I M AT I O N S
• Use sparingly.
• Hard to do good, accessible UX with animations anyway.
• JavaScript animations are only performant if the main JS thread is not
occupied.
• CSS animations can be better because they’re not on the JS thread.
Investigate using the GPU to further enhance performant.
• Tend to burn battery.
R E A C T P E R F T I P S
S H O U L D C O M P O N E N T U P D AT E
• React components have a lifecycle method called
shouldComponentUpdate() that React runs in order to tell if it should re-
render the component or not.
• For components that never re-render, always return false.
• For perf bottlenecks, implement your own shouldComponentUpdate.
• For other components, leave them alone. It can introduce hard-to-find
bugs.
R E A C T P E R F T O O L I N G
• printInclusive – include lifecycle methods
• printExclusive – exclude lifecycle methods
• printWasted – TIME/BATTERY YOU ARE WASTING YOU IDIOT
R E N D E R F E W E R I T E M S
• reddit has this problem and Facebook had it.
• One feed item has many tiny components and each page has many feed
items.
• By only rendering the feed items visible on the page, you save React a
significant amount of re-rendering.
• Hidden menus / actions? Only render them when shown.
– J O R D A N WA L K E ( R E A C T C O R E T E A M )
“The amount of data you have, should remain independent from the
amount of data rendered.”
D R A W W I T H I N T H E L I N E S
• Stop abusing lifecycle methods.
• Use refs only when what you want cannot be done another way.
• When you must listen for DOM events, be sure to clean up after yourself in
componentWillUnmount.
R E A C T F U L R E A C T
• Careful what you stick on state. State should be reserved for mutable data
that the component needs to react to changes for.
• There is a point where you’re breaking a component into too small of
components.
• Sometimes is just better to have a button with a style class and that’s it!
W E B PA C K
• Webpack can break your page into chunks that get loaded only on the
necessary page.
• Import only modules that you need.
• If you can’t switch to Webpack, uglify can at least get you dead code
elimination.
• Otherwise npm dedupe can help you do it by hand.
R O L L U P. J S
• YAJSP™ (yet another JavaScript packager, like Browserify or Webpack)
• … the resulting bundle is always smaller than the Browserify or Webpack
equivalent, because ES2015 modules are inherently more efficient than
CommonJS modules. You can even eliminate unused library code with
tree-shaking.
S V G S I N R E A C T A R E E X P E N S I V E
• Use sparingly.
• Don’t make them React components if you can help it.
W R I T E T H E A P P F I R S T
• Don’t spend too much optimizing code preemptively or code that isn’t
really a bottleneck.
• Prefer readability when possible.
• After getting readable code down then go back and optimize and hack
around the bottlenecks.
• Document hacks well.
H T T P 2
R E M E M B E R E V E RY T H I N G Y O U K N O W ?
I T ’ S W R O N G , L O L .
H T T P 2
• SPDY
• Leaves connection open, eliminating costly handshakes.
• Uses compression inherently.
• Multiplexes assets sent down.
H T T P 2 A N T I PAT T E R N S
• Concatenating files.
• Spriting images.
• Serving statics from a separate domain.
• Minifiying assets.
W H E N ?
S P D Y / H T T P 2 S U P P O R T
• All mobile browsers (except Opera Mini and Blackberry) support it.
• Yeah, even the stock Android browser. Weird.
• Firefox, Chrome, and Opera since forever.
• IE 11+ and Safari 8+.
T H AT ’ S ~ 8 0 % O F G L O B A L U S E R S .
A N D J U S T A B O U T A L L M O B I L E U S E R S .
F I N
B R I A N H O LT
@ H O LT B T
Watch the video with slide synchronization on
InfoQ.com!
http://www.infoq.com/presentations/react-
reddit-mobile

More Related Content

What's hot

5 Ways to Awesome-ize Your (PHP) Code
5 Ways to Awesome-ize Your (PHP) Code5 Ways to Awesome-ize Your (PHP) Code
5 Ways to Awesome-ize Your (PHP) CodeJeremy Kendall
 
Game Changing Dependency Management
Game Changing Dependency ManagementGame Changing Dependency Management
Game Changing Dependency ManagementJeremy Kendall
 
Talk about java
Talk about javaTalk about java
Talk about javaDavis Chen
 
Getting Started with WordPress Development
Getting Started with WordPress DevelopmentGetting Started with WordPress Development
Getting Started with WordPress DevelopmentRyan Welcher
 

What's hot (6)

5 Ways to Awesome-ize Your (PHP) Code
5 Ways to Awesome-ize Your (PHP) Code5 Ways to Awesome-ize Your (PHP) Code
5 Ways to Awesome-ize Your (PHP) Code
 
EhTrace -- RoP Hooks
EhTrace -- RoP HooksEhTrace -- RoP Hooks
EhTrace -- RoP Hooks
 
Game Changing Dependency Management
Game Changing Dependency ManagementGame Changing Dependency Management
Game Changing Dependency Management
 
Talk about java
Talk about javaTalk about java
Talk about java
 
Xml Zoe
Xml ZoeXml Zoe
Xml Zoe
 
Getting Started with WordPress Development
Getting Started with WordPress DevelopmentGetting Started with WordPress Development
Getting Started with WordPress Development
 

Similar to Using React for the Mobile Web

High quality Front-End
High quality Front-EndHigh quality Front-End
High quality Front-EndDavid Simons
 
The 12 Factor App
The 12 Factor AppThe 12 Factor App
The 12 Factor Apprudiyardley
 
200,000 Lines Later: Our Journey to Manageable Puppet Code
200,000 Lines Later: Our Journey to Manageable Puppet Code200,000 Lines Later: Our Journey to Manageable Puppet Code
200,000 Lines Later: Our Journey to Manageable Puppet CodeDavid Danzilio
 
Best Practices for WordPress in Enterprise
Best Practices for WordPress in EnterpriseBest Practices for WordPress in Enterprise
Best Practices for WordPress in EnterpriseTaylor Lovett
 
Best practices-wordpress-enterprise
Best practices-wordpress-enterpriseBest practices-wordpress-enterprise
Best practices-wordpress-enterpriseTaylor Lovett
 
Get Speed 100 - Optimization techniques to make your website fast
Get Speed 100 - Optimization techniques to make your website fastGet Speed 100 - Optimization techniques to make your website fast
Get Speed 100 - Optimization techniques to make your website fastAlexander Dos Santos
 
Community and Github: 7/27/2011
Community and Github: 7/27/2011Community and Github: 7/27/2011
Community and Github: 7/27/2011Andy Lester
 
The Good, the Bad and the Ugly things to do with android
The Good, the Bad and the Ugly things to do with androidThe Good, the Bad and the Ugly things to do with android
The Good, the Bad and the Ugly things to do with androidStanojko Markovik
 
Naked and afraid Offline mobile
Naked and afraid Offline mobileNaked and afraid Offline mobile
Naked and afraid Offline mobiledevObjective
 
WHAT / WHY / HOW WE’RE ENGINEERING AT SMARTSTUDY (English)
WHAT / WHY / HOW WE’RE ENGINEERING AT SMARTSTUDY (English)WHAT / WHY / HOW WE’RE ENGINEERING AT SMARTSTUDY (English)
WHAT / WHY / HOW WE’RE ENGINEERING AT SMARTSTUDY (English)Hyun-woo Park
 
Building a Data Ingestion & Processing Pipeline with Spark & Airflow
Building a Data Ingestion & Processing Pipeline with Spark & AirflowBuilding a Data Ingestion & Processing Pipeline with Spark & Airflow
Building a Data Ingestion & Processing Pipeline with Spark & AirflowTom Lous
 
Prototyping for mobile
Prototyping for mobilePrototyping for mobile
Prototyping for mobileMemi Beltrame
 
Docker for Development
Docker for DevelopmentDocker for Development
Docker for Developmentallingeek
 
Getting Started with Drupal
Getting Started with DrupalGetting Started with Drupal
Getting Started with DrupalPantheon
 
The Characteristics of a Successful SPA
The Characteristics of a Successful SPAThe Characteristics of a Successful SPA
The Characteristics of a Successful SPAGil Fink
 
We’re Going Mobile! Great! Wait… What Does That Mean?
We’re Going Mobile! Great! Wait… What Does That Mean?We’re Going Mobile! Great! Wait… What Does That Mean?
We’re Going Mobile! Great! Wait… What Does That Mean?STC-Philadelphia Metro Chapter
 

Similar to Using React for the Mobile Web (20)

High quality Front-End
High quality Front-EndHigh quality Front-End
High quality Front-End
 
The 12 Factor App
The 12 Factor AppThe 12 Factor App
The 12 Factor App
 
200,000 Lines Later: Our Journey to Manageable Puppet Code
200,000 Lines Later: Our Journey to Manageable Puppet Code200,000 Lines Later: Our Journey to Manageable Puppet Code
200,000 Lines Later: Our Journey to Manageable Puppet Code
 
Best Practices for WordPress in Enterprise
Best Practices for WordPress in EnterpriseBest Practices for WordPress in Enterprise
Best Practices for WordPress in Enterprise
 
Deployments in one click!
Deployments in one click!Deployments in one click!
Deployments in one click!
 
Best practices-wordpress-enterprise
Best practices-wordpress-enterpriseBest practices-wordpress-enterprise
Best practices-wordpress-enterprise
 
Get Speed 100 - Optimization techniques to make your website fast
Get Speed 100 - Optimization techniques to make your website fastGet Speed 100 - Optimization techniques to make your website fast
Get Speed 100 - Optimization techniques to make your website fast
 
Community and Github: 7/27/2011
Community and Github: 7/27/2011Community and Github: 7/27/2011
Community and Github: 7/27/2011
 
The Good, the Bad and the Ugly things to do with android
The Good, the Bad and the Ugly things to do with androidThe Good, the Bad and the Ugly things to do with android
The Good, the Bad and the Ugly things to do with android
 
Naked and afraid Offline Mobile
Naked and afraid Offline MobileNaked and afraid Offline Mobile
Naked and afraid Offline Mobile
 
Naked and afraid Offline mobile
Naked and afraid Offline mobileNaked and afraid Offline mobile
Naked and afraid Offline mobile
 
WHAT / WHY / HOW WE’RE ENGINEERING AT SMARTSTUDY (English)
WHAT / WHY / HOW WE’RE ENGINEERING AT SMARTSTUDY (English)WHAT / WHY / HOW WE’RE ENGINEERING AT SMARTSTUDY (English)
WHAT / WHY / HOW WE’RE ENGINEERING AT SMARTSTUDY (English)
 
Monorepo at Pinterest
Monorepo at PinterestMonorepo at Pinterest
Monorepo at Pinterest
 
SOA Latam 2015
SOA Latam 2015SOA Latam 2015
SOA Latam 2015
 
Building a Data Ingestion & Processing Pipeline with Spark & Airflow
Building a Data Ingestion & Processing Pipeline with Spark & AirflowBuilding a Data Ingestion & Processing Pipeline with Spark & Airflow
Building a Data Ingestion & Processing Pipeline with Spark & Airflow
 
Prototyping for mobile
Prototyping for mobilePrototyping for mobile
Prototyping for mobile
 
Docker for Development
Docker for DevelopmentDocker for Development
Docker for Development
 
Getting Started with Drupal
Getting Started with DrupalGetting Started with Drupal
Getting Started with Drupal
 
The Characteristics of a Successful SPA
The Characteristics of a Successful SPAThe Characteristics of a Successful SPA
The Characteristics of a Successful SPA
 
We’re Going Mobile! Great! Wait… What Does That Mean?
We’re Going Mobile! Great! Wait… What Does That Mean?We’re Going Mobile! Great! Wait… What Does That Mean?
We’re Going Mobile! Great! Wait… What Does That Mean?
 

More from C4Media

Streaming a Million Likes/Second: Real-Time Interactions on Live Video
Streaming a Million Likes/Second: Real-Time Interactions on Live VideoStreaming a Million Likes/Second: Real-Time Interactions on Live Video
Streaming a Million Likes/Second: Real-Time Interactions on Live VideoC4Media
 
Next Generation Client APIs in Envoy Mobile
Next Generation Client APIs in Envoy MobileNext Generation Client APIs in Envoy Mobile
Next Generation Client APIs in Envoy MobileC4Media
 
Software Teams and Teamwork Trends Report Q1 2020
Software Teams and Teamwork Trends Report Q1 2020Software Teams and Teamwork Trends Report Q1 2020
Software Teams and Teamwork Trends Report Q1 2020C4Media
 
Understand the Trade-offs Using Compilers for Java Applications
Understand the Trade-offs Using Compilers for Java ApplicationsUnderstand the Trade-offs Using Compilers for Java Applications
Understand the Trade-offs Using Compilers for Java ApplicationsC4Media
 
Kafka Needs No Keeper
Kafka Needs No KeeperKafka Needs No Keeper
Kafka Needs No KeeperC4Media
 
High Performing Teams Act Like Owners
High Performing Teams Act Like OwnersHigh Performing Teams Act Like Owners
High Performing Teams Act Like OwnersC4Media
 
Does Java Need Inline Types? What Project Valhalla Can Bring to Java
Does Java Need Inline Types? What Project Valhalla Can Bring to JavaDoes Java Need Inline Types? What Project Valhalla Can Bring to Java
Does Java Need Inline Types? What Project Valhalla Can Bring to JavaC4Media
 
Service Meshes- The Ultimate Guide
Service Meshes- The Ultimate GuideService Meshes- The Ultimate Guide
Service Meshes- The Ultimate GuideC4Media
 
Shifting Left with Cloud Native CI/CD
Shifting Left with Cloud Native CI/CDShifting Left with Cloud Native CI/CD
Shifting Left with Cloud Native CI/CDC4Media
 
CI/CD for Machine Learning
CI/CD for Machine LearningCI/CD for Machine Learning
CI/CD for Machine LearningC4Media
 
Fault Tolerance at Speed
Fault Tolerance at SpeedFault Tolerance at Speed
Fault Tolerance at SpeedC4Media
 
Architectures That Scale Deep - Regaining Control in Deep Systems
Architectures That Scale Deep - Regaining Control in Deep SystemsArchitectures That Scale Deep - Regaining Control in Deep Systems
Architectures That Scale Deep - Regaining Control in Deep SystemsC4Media
 
ML in the Browser: Interactive Experiences with Tensorflow.js
ML in the Browser: Interactive Experiences with Tensorflow.jsML in the Browser: Interactive Experiences with Tensorflow.js
ML in the Browser: Interactive Experiences with Tensorflow.jsC4Media
 
Build Your Own WebAssembly Compiler
Build Your Own WebAssembly CompilerBuild Your Own WebAssembly Compiler
Build Your Own WebAssembly CompilerC4Media
 
User & Device Identity for Microservices @ Netflix Scale
User & Device Identity for Microservices @ Netflix ScaleUser & Device Identity for Microservices @ Netflix Scale
User & Device Identity for Microservices @ Netflix ScaleC4Media
 
Scaling Patterns for Netflix's Edge
Scaling Patterns for Netflix's EdgeScaling Patterns for Netflix's Edge
Scaling Patterns for Netflix's EdgeC4Media
 
Make Your Electron App Feel at Home Everywhere
Make Your Electron App Feel at Home EverywhereMake Your Electron App Feel at Home Everywhere
Make Your Electron App Feel at Home EverywhereC4Media
 
The Talk You've Been Await-ing For
The Talk You've Been Await-ing ForThe Talk You've Been Await-ing For
The Talk You've Been Await-ing ForC4Media
 
Future of Data Engineering
Future of Data EngineeringFuture of Data Engineering
Future of Data EngineeringC4Media
 
Automated Testing for Terraform, Docker, Packer, Kubernetes, and More
Automated Testing for Terraform, Docker, Packer, Kubernetes, and MoreAutomated Testing for Terraform, Docker, Packer, Kubernetes, and More
Automated Testing for Terraform, Docker, Packer, Kubernetes, and MoreC4Media
 

More from C4Media (20)

Streaming a Million Likes/Second: Real-Time Interactions on Live Video
Streaming a Million Likes/Second: Real-Time Interactions on Live VideoStreaming a Million Likes/Second: Real-Time Interactions on Live Video
Streaming a Million Likes/Second: Real-Time Interactions on Live Video
 
Next Generation Client APIs in Envoy Mobile
Next Generation Client APIs in Envoy MobileNext Generation Client APIs in Envoy Mobile
Next Generation Client APIs in Envoy Mobile
 
Software Teams and Teamwork Trends Report Q1 2020
Software Teams and Teamwork Trends Report Q1 2020Software Teams and Teamwork Trends Report Q1 2020
Software Teams and Teamwork Trends Report Q1 2020
 
Understand the Trade-offs Using Compilers for Java Applications
Understand the Trade-offs Using Compilers for Java ApplicationsUnderstand the Trade-offs Using Compilers for Java Applications
Understand the Trade-offs Using Compilers for Java Applications
 
Kafka Needs No Keeper
Kafka Needs No KeeperKafka Needs No Keeper
Kafka Needs No Keeper
 
High Performing Teams Act Like Owners
High Performing Teams Act Like OwnersHigh Performing Teams Act Like Owners
High Performing Teams Act Like Owners
 
Does Java Need Inline Types? What Project Valhalla Can Bring to Java
Does Java Need Inline Types? What Project Valhalla Can Bring to JavaDoes Java Need Inline Types? What Project Valhalla Can Bring to Java
Does Java Need Inline Types? What Project Valhalla Can Bring to Java
 
Service Meshes- The Ultimate Guide
Service Meshes- The Ultimate GuideService Meshes- The Ultimate Guide
Service Meshes- The Ultimate Guide
 
Shifting Left with Cloud Native CI/CD
Shifting Left with Cloud Native CI/CDShifting Left with Cloud Native CI/CD
Shifting Left with Cloud Native CI/CD
 
CI/CD for Machine Learning
CI/CD for Machine LearningCI/CD for Machine Learning
CI/CD for Machine Learning
 
Fault Tolerance at Speed
Fault Tolerance at SpeedFault Tolerance at Speed
Fault Tolerance at Speed
 
Architectures That Scale Deep - Regaining Control in Deep Systems
Architectures That Scale Deep - Regaining Control in Deep SystemsArchitectures That Scale Deep - Regaining Control in Deep Systems
Architectures That Scale Deep - Regaining Control in Deep Systems
 
ML in the Browser: Interactive Experiences with Tensorflow.js
ML in the Browser: Interactive Experiences with Tensorflow.jsML in the Browser: Interactive Experiences with Tensorflow.js
ML in the Browser: Interactive Experiences with Tensorflow.js
 
Build Your Own WebAssembly Compiler
Build Your Own WebAssembly CompilerBuild Your Own WebAssembly Compiler
Build Your Own WebAssembly Compiler
 
User & Device Identity for Microservices @ Netflix Scale
User & Device Identity for Microservices @ Netflix ScaleUser & Device Identity for Microservices @ Netflix Scale
User & Device Identity for Microservices @ Netflix Scale
 
Scaling Patterns for Netflix's Edge
Scaling Patterns for Netflix's EdgeScaling Patterns for Netflix's Edge
Scaling Patterns for Netflix's Edge
 
Make Your Electron App Feel at Home Everywhere
Make Your Electron App Feel at Home EverywhereMake Your Electron App Feel at Home Everywhere
Make Your Electron App Feel at Home Everywhere
 
The Talk You've Been Await-ing For
The Talk You've Been Await-ing ForThe Talk You've Been Await-ing For
The Talk You've Been Await-ing For
 
Future of Data Engineering
Future of Data EngineeringFuture of Data Engineering
Future of Data Engineering
 
Automated Testing for Terraform, Docker, Packer, Kubernetes, and More
Automated Testing for Terraform, Docker, Packer, Kubernetes, and MoreAutomated Testing for Terraform, Docker, Packer, Kubernetes, and More
Automated Testing for Terraform, Docker, Packer, Kubernetes, and More
 

Recently uploaded

Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
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
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
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
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
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
 
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
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 
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
 

Recently uploaded (20)

Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
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
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
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
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
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
 
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
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 
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
 

Using React for the Mobile Web

  • 1. W R I T I N G R E A C T F O R T H E M O B I L E W E B C A S E S T U D Y: B R I A N H O LT @ H O LT B T – B R I @ N H O . LT
  • 2. InfoQ.com: News & Community Site • 750,000 unique visitors/month • Published in 4 languages (English, Chinese, Japanese and Brazilian Portuguese) • Post content from our QCon conferences • News 15-20 / week • Articles 3-4 / week • Presentations (videos) 12-15 / week • Interviews 2-3 / week • Books 1 / month Watch the video with slide synchronization on InfoQ.com! http://www.infoq.com/presentations/ react-reddit-mobile
  • 3. Purpose of QCon - to empower software development by facilitating the spread of knowledge and innovation Strategy - practitioner-driven conference designed for YOU: influencers of change and innovation in your teams - speakers and topics driving the evolution and innovation - connecting and catalyzing the influencers and innovators Highlights - attended by more than 12,000 delegates since 2007 - held in 9 cities worldwide Presented at QCon San Francisco www.qconsf.com
  • 4. W H Y I S W R I T I N G R E A C T D I F F E R E N T F O R T H E M O B I L E W E B ?
  • 5. I T ’ S N O T.
  • 6. F I N B R I A N H O LT @ H O LT B T
  • 7. L O L J K
  • 8. P E R F
  • 9. P E R F M AT T E R S O N M O B I L E . A L O T.
  • 10. W R I T I N G P E R F O R M A N T R E A C T B R I A N H O LT @ H O LT B T
  • 11. W E B P E R F O R M A N C E B R I A N H O LT @ H O LT B T
  • 12. P E R F M AT T E R S • Data speed • Data cost • Battery drain • Bad UX • Longer load time is LESS ****ING MONEY.
  • 13.
  • 14.
  • 15.
  • 17. lol
  • 19. ****
  • 20. G E N E R A L P E R F T I P S
  • 21. U S E I M A G E S S PA R I N G LY. O P T I M I Z E T H E O N E S Y O U D O U S E .
  • 22. C A C H E
  • 23. C A C H E • Cache images as long as possible. • Consider separating scripts and styles that change frequently from scripts and styles that remain the same. • e.g. Separate your vendor code like Bootstrap from your app code. • Use naming conventions to invalidate cache.
  • 24. H T T P C A C H I N G I S N ’ T A S G R E AT A S Y O U T H I N K • IE, Chrome, Safari and Firefox only keep ~200MB of cache on hand. • Android keeps 80MB of cache. • Mobile Safari has no HTTP cache.
  • 25. D O N ’ T U S E A W E B F O N T. T E L L Y O U R D E S I G N E R T O * * * * O F F I F H E / S H E WA N T S T O .
  • 26. I C O N F O N T S A R E * * * * T O O . T H E Y ’ R E B I G A N D T H E Y ’ R E H A R D T O M A K E A C C E S S I B L E .
  • 27. Y O U ’ R E S L O W I N G D O W N Y O U R W E B S I T E T O M A K E I T L E S S A C C E S S I B L E .
  • 28.
  • 29. G O O D J O B .
  • 30. C R I T I C A L R E N D E R I N G PAT H • This is a psychology game. You want the fastest perceived page load. • Defer anything not critical to the first paint to after it. • However, once you have had your first paint, starting loading everything as fast as you can!
  • 31. F I L E S I Z E • Having just gone to China where data was real expensive to use, CUT DOWN YOUR ****ING FILE SIZES. • Only include polyfills (especially with Babel) you use. • e.g. with lodash, only include methods you use. • Dedupe your dependencies.
  • 32.
  • 33. W E ' D L I K E T O I M A G I N E T H AT T H E WAY A W E B PA G E L O A D S I S T H I S : 1. Browser opens connection to yoursite.com, does DNS/TCP/SSL setup. 2. Browser downloads the document (HTML). 3. As soon as the browser is done downloading the document, the browser starts downloading all the document's sub resources at the same time. 4. Browser parses the document and fills in the necessary sub resources once they've been downloaded. source: nateberkopec.com/2015/11/05/page-weight-doesnt-matter.html
  • 34. H E R E ' S W H AT A C T U A L LY H A P P E N S : 1. Browser opens connection to yoursite.com, does DNS/TCP/SSL setup. 2. Browser downloads the document (HTML). 3. Browser starts parsing the document. When the parser encounters a subresource, it opens a connection and downloads it. 4. Parse the document? Nah man, I'm gonna wait for this script to download and execute. If the subresource is an external script tag, the parser stops, waits until it the script has downloaded, executes the entire script, and then moves on. 5. As soon as the parser stops and has to wait for an external script to download, it sends ahead something called a preloader. The preloader may notice and begin downloading resources if it understands how to (hint: a very popular Javascript pattern prevents this). source: nateberkopec.com/2015/11/05/page-weight-doesnt-matter.html
  • 35.
  • 36. W H AT T O D O • Don't stop the parser. • Get out of the browser preloader's way. • Utilize HTTP caching - but not too much. • Use the Resource Hint API. source: nateberkopec.com/2015/11/05/page-weight-doesnt-matter.html
  • 37. R E S O U R C E H I N T S • preconnect – A neat little trick to let the browser know about things that it couldn’t otherwise. A good example would be a script tag you’re going to inject later. • prefetch – Great for grabbing resources for the next page the user is going to hit. If you’re in a funnel and you know where the user is going next, prefect those resources. • prerender – Grab and actually pretender an HTML resource. Great for something like Google Instant Pages.
  • 38. U S E A S Y N C A N D D E F E R AT T R I B U T E S O N Y O U R S C R I P T TA G S normal async defer source: growingwiththeweb.com/2014/02/async-vs-defer-attributes.html
  • 39. W H AT AT T R I B U T E W H E N • Typically you want to use async where possible, then defer then no attribute. Here are some general rules to follow: • If the script is modular and does not rely on any scripts then use async. • If the script relies upon or is relied upon by another script then use defer. • If the script is small and is relied upon by an async script then use an inline script with no attributes placed above the async scripts. source: growingwiththeweb.com/2014/02/async-vs-defer-attributes.html
  • 40. D E F E R G U A R A N T E E S O R D E R O F E X E C U T I O N . A S Y N C D O E S N O T.
  • 41. I F Y O U R T R A C K I N G O R A N A LY T I C S A R E N O T A S Y N C , Y O U M A K E K I T T Y S A D
  • 42. A N I M AT I O N S • Use sparingly. • Hard to do good, accessible UX with animations anyway. • JavaScript animations are only performant if the main JS thread is not occupied. • CSS animations can be better because they’re not on the JS thread. Investigate using the GPU to further enhance performant. • Tend to burn battery.
  • 43. R E A C T P E R F T I P S
  • 44. S H O U L D C O M P O N E N T U P D AT E • React components have a lifecycle method called shouldComponentUpdate() that React runs in order to tell if it should re- render the component or not. • For components that never re-render, always return false. • For perf bottlenecks, implement your own shouldComponentUpdate. • For other components, leave them alone. It can introduce hard-to-find bugs.
  • 45. R E A C T P E R F T O O L I N G • printInclusive – include lifecycle methods • printExclusive – exclude lifecycle methods • printWasted – TIME/BATTERY YOU ARE WASTING YOU IDIOT
  • 46.
  • 47. R E N D E R F E W E R I T E M S • reddit has this problem and Facebook had it. • One feed item has many tiny components and each page has many feed items. • By only rendering the feed items visible on the page, you save React a significant amount of re-rendering. • Hidden menus / actions? Only render them when shown.
  • 48. – J O R D A N WA L K E ( R E A C T C O R E T E A M ) “The amount of data you have, should remain independent from the amount of data rendered.”
  • 49. D R A W W I T H I N T H E L I N E S • Stop abusing lifecycle methods. • Use refs only when what you want cannot be done another way. • When you must listen for DOM events, be sure to clean up after yourself in componentWillUnmount.
  • 50. R E A C T F U L R E A C T • Careful what you stick on state. State should be reserved for mutable data that the component needs to react to changes for. • There is a point where you’re breaking a component into too small of components. • Sometimes is just better to have a button with a style class and that’s it!
  • 51. W E B PA C K • Webpack can break your page into chunks that get loaded only on the necessary page. • Import only modules that you need. • If you can’t switch to Webpack, uglify can at least get you dead code elimination. • Otherwise npm dedupe can help you do it by hand.
  • 52. R O L L U P. J S • YAJSP™ (yet another JavaScript packager, like Browserify or Webpack) • … the resulting bundle is always smaller than the Browserify or Webpack equivalent, because ES2015 modules are inherently more efficient than CommonJS modules. You can even eliminate unused library code with tree-shaking.
  • 53. S V G S I N R E A C T A R E E X P E N S I V E • Use sparingly. • Don’t make them React components if you can help it.
  • 54. W R I T E T H E A P P F I R S T • Don’t spend too much optimizing code preemptively or code that isn’t really a bottleneck. • Prefer readability when possible. • After getting readable code down then go back and optimize and hack around the bottlenecks. • Document hacks well.
  • 55. H T T P 2
  • 56. R E M E M B E R E V E RY T H I N G Y O U K N O W ?
  • 57. I T ’ S W R O N G , L O L .
  • 58. H T T P 2 • SPDY • Leaves connection open, eliminating costly handshakes. • Uses compression inherently. • Multiplexes assets sent down.
  • 59. H T T P 2 A N T I PAT T E R N S • Concatenating files. • Spriting images. • Serving statics from a separate domain. • Minifiying assets.
  • 60. W H E N ?
  • 61.
  • 62. S P D Y / H T T P 2 S U P P O R T • All mobile browsers (except Opera Mini and Blackberry) support it. • Yeah, even the stock Android browser. Weird. • Firefox, Chrome, and Opera since forever. • IE 11+ and Safari 8+.
  • 63. T H AT ’ S ~ 8 0 % O F G L O B A L U S E R S . A N D J U S T A B O U T A L L M O B I L E U S E R S .
  • 64. F I N B R I A N H O LT @ H O LT B T
  • 65. Watch the video with slide synchronization on InfoQ.com! http://www.infoq.com/presentations/react- reddit-mobile