SlideShare a Scribd company logo
5 Quick JavaScript
Performance
Improvement Tips
30 January 2014
Twitter handle:
@therockncoder
The Rock n Coder
• http://therockncoder.blogspot.com	

• http://www.youtube.com/user/rockncoder	

• https://github.com/Rockncoder	

• http://www.slideshare.net/rockncoder
Our Agenda
• Why Performance Matters	

• 5 Performance Tips	

• Resources	

• Summary
Why Performance
Matters?
Why Performance
Matters?
• 47% of consumers expect a 2 second page
load	


• 40% abandon a page that takes 3 seconds
or more to load	


• A 1 second delay in page response can

result in a 7% reduction in conversions
If an e-commerce site is making
$100,000 a day in sales, a 1 second
page delay could potentially cost you
$2.5 million in lost sales every year
We should forget about small efficiencies, say
about 97% of the time: premature optimization
is the root of all evil.Yet we should not pass up
our opportunities in that critical 3%.
D. Knuth
5 Performance Tips
Tip #5
Use as few files as
possible
Use as few files as
possible

• Browser can load multiple files at a time	

• But only one JS file at a time	

• Concatenate multiple JS file into one	

• Compress JS files	

• Prefer JS at the bottom of the HTML file
Tip #4
Prefer local variables
Prefer local variables
• Variables in scope found quicker	

• JS search local scope, then global	

• with creates a new scope level ahead of
local	


• closures also create new scope level
Var Scoping Demo
Prefer local variables
• Property chains similar to var scoping	

• Objects closer in the chain found quicker
Property Chain Demo
Tip #3
Reduce the work done
in loops
Reduce the work done
in loops

• No real speed difference between: for, while
and do_while	


• Avoid for_in	

• (Watch library based for_each)
Tip #2
Watch your plugins
Watch your plugins
• Know what your plugins do	

• Be sure to evaluate different plugins	

• Example jQuery.js or Zepto.js
jQuery Demo
Tip #1
Avoid the DOM
Avoid the DOM
• The DOM is REALLY Slow	

• Avoid accessing it when possible	

• Do work offline then update DOM
DOM Access Demo
Resources
Resources
• Microsoft Ajax Minifier


http://ajaxmin.codeplex.com/	


• Google Closure Tools


https://developers.google.com/closure/	


• Yahoo YSlow


http://developer.yahoo.com/yslow/
Books
• High Performance JavaScript

Nicholas C. Zakas	


• JavaScript Ninja


John Resig & Bear Bibeaults	


• JavaScript: The Good Parts

Douglas Crockford

Summary
Summary
• Avoid the DOM 	

• Watch your plugins 	

• Reduce the work done in loops 	

• Prefer local variables	

• Use as few files as possible
The Rock n Coder
• http://therockncoder.blogspot.com	

• http://www.youtube.com/user/rockncoder	

• https://github.com/Rockncoder	

• http://www.slideshare.net/rockncoder

More Related Content

What's hot (20)

PDF
Get Hip with JHipster - Denver JUG 2015
Matt Raible
 
PDF
What Multisite can do for You - Anthony Cole - WordCamp Sydney 2012
WordCamp Sydney
 
PDF
Testing Angular 2 Applications - HTML5 Denver 2016
Matt Raible
 
PDF
Understanding XHProf: Pinpointing Why Your Site is Slow and How to Fix it - S...
Ezra Gildesgame
 
PDF
jQuery Conference San Diego 2014 - Web Performance
dmethvin
 
PDF
Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - Devoxx 2015
Matt Raible
 
PDF
Testing Mobile JavaScript
jeresig
 
PDF
Getting Started with Angular - Stormpath Webinar, January 2017
Matt Raible
 
PDF
WAG the Blog
Evan Volgas
 
PDF
Kickstarter Your Node.JS Application
Hengki Sihombing
 
PDF
Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - GeekOut 2016
Matt Raible
 
PDF
On Selecting JavaScript Frameworks (Women Who Code 10/15)
Zoe Landon
 
PDF
Responsive, adaptive and responsible - keynote at NebraskaJS
Christian Heilmann
 
PDF
Build the mobile web you want
k88hudson
 
PPTX
Optimizing Your Site for Holiday Traffic
WP Engine UK
 
KEY
New Perspectives on Performance
mennovanslooten
 
PDF
Task runners + theming automating your workflow
Joshua Gilmer
 
PDF
Hello npm
Muyuu Fujita
 
PDF
Get Hip with JHipster - Colorado Springs OSS Meetup April 2016
Matt Raible
 
PPTX
HyperDB, MySQL Performance, & Flavors of MySQL
Evan Volgas
 
Get Hip with JHipster - Denver JUG 2015
Matt Raible
 
What Multisite can do for You - Anthony Cole - WordCamp Sydney 2012
WordCamp Sydney
 
Testing Angular 2 Applications - HTML5 Denver 2016
Matt Raible
 
Understanding XHProf: Pinpointing Why Your Site is Slow and How to Fix it - S...
Ezra Gildesgame
 
jQuery Conference San Diego 2014 - Web Performance
dmethvin
 
Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - Devoxx 2015
Matt Raible
 
Testing Mobile JavaScript
jeresig
 
Getting Started with Angular - Stormpath Webinar, January 2017
Matt Raible
 
WAG the Blog
Evan Volgas
 
Kickstarter Your Node.JS Application
Hengki Sihombing
 
Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - GeekOut 2016
Matt Raible
 
On Selecting JavaScript Frameworks (Women Who Code 10/15)
Zoe Landon
 
Responsive, adaptive and responsible - keynote at NebraskaJS
Christian Heilmann
 
Build the mobile web you want
k88hudson
 
Optimizing Your Site for Holiday Traffic
WP Engine UK
 
New Perspectives on Performance
mennovanslooten
 
Task runners + theming automating your workflow
Joshua Gilmer
 
Hello npm
Muyuu Fujita
 
Get Hip with JHipster - Colorado Springs OSS Meetup April 2016
Matt Raible
 
HyperDB, MySQL Performance, & Flavors of MySQL
Evan Volgas
 

Similar to 5 Quick JavaScript Performance Improvement Tips (20)

PPTX
30 JavaScript optimization tips
Hovhannes Avoyan
 
PPTX
Java script performance tips
Shakti Shrestha
 
PPT
High Performance Ajax Applications 1197671494632682 2
Niti Chotkaew
 
PPT
High Performance Ajax Applications
Julien Lecomte
 
KEY
A rough guide to JavaScript Performance
allmarkedup
 
PDF
Performance Optimization and JavaScript Best Practices
Doris Chen
 
PPTX
JavaScript front end performance optimizations
Chris Love
 
PPT
Ajax Performance
kaven yan
 
PDF
Developing High Performance Web Apps
Timothy Fisher
 
PPT
Performance optimization - JavaScript
Filip Mares
 
PPTX
7 tips for javascript rich ajax websites
oazabir
 
PPT
Web performance essentials - Goodies
Jerry Emmanuel
 
PDF
How DRY impacts JavaScript performance // Faster JavaScript execution for the...
Mathias Bynens
 
PDF
10 Groovy Little JavaScript Tips
Troy Miles
 
PDF
Ajax Performance Tuning and Best Practices
Doris Chen
 
PPT
Os Smarr
oscon2007
 
PPT
Smarr Oscon 2007
briandemant
 
PDF
Client Side Performance In Web Applications
vladungureanu
 
PDF
Front-end optimisation & jQuery Internals (Pycon)
Artur Cistov
 
PPTX
Creating high-performance-web-sites
chaos_bit
 
30 JavaScript optimization tips
Hovhannes Avoyan
 
Java script performance tips
Shakti Shrestha
 
High Performance Ajax Applications 1197671494632682 2
Niti Chotkaew
 
High Performance Ajax Applications
Julien Lecomte
 
A rough guide to JavaScript Performance
allmarkedup
 
Performance Optimization and JavaScript Best Practices
Doris Chen
 
JavaScript front end performance optimizations
Chris Love
 
Ajax Performance
kaven yan
 
Developing High Performance Web Apps
Timothy Fisher
 
Performance optimization - JavaScript
Filip Mares
 
7 tips for javascript rich ajax websites
oazabir
 
Web performance essentials - Goodies
Jerry Emmanuel
 
How DRY impacts JavaScript performance // Faster JavaScript execution for the...
Mathias Bynens
 
10 Groovy Little JavaScript Tips
Troy Miles
 
Ajax Performance Tuning and Best Practices
Doris Chen
 
Os Smarr
oscon2007
 
Smarr Oscon 2007
briandemant
 
Client Side Performance In Web Applications
vladungureanu
 
Front-end optimisation & jQuery Internals (Pycon)
Artur Cistov
 
Creating high-performance-web-sites
chaos_bit
 
Ad

More from Troy Miles (20)

PDF
Fast C++ Web Servers
Troy Miles
 
PDF
Node Boot Camp
Troy Miles
 
PDF
AWS Lambda Function with Kotlin
Troy Miles
 
PDF
React Native One Day
Troy Miles
 
PDF
React Native Evening
Troy Miles
 
PDF
Intro to React
Troy Miles
 
PDF
React Development with the MERN Stack
Troy Miles
 
PDF
Angular Application Testing
Troy Miles
 
PDF
ReactJS.NET
Troy Miles
 
PDF
What is Angular version 4?
Troy Miles
 
PDF
Angular Weekend
Troy Miles
 
PDF
From MEAN to the MERN Stack
Troy Miles
 
PDF
Functional Programming in JavaScript
Troy Miles
 
PDF
Functional Programming in Clojure
Troy Miles
 
PDF
MEAN Stack Warm-up
Troy Miles
 
PDF
The JavaScript You Wished You Knew
Troy Miles
 
PDF
Game Design and Development Workshop Day 1
Troy Miles
 
PDF
Build a Game in 60 minutes
Troy Miles
 
PDF
Quick & Dirty & MEAN
Troy Miles
 
PDF
A Quick Intro to ReactiveX
Troy Miles
 
Fast C++ Web Servers
Troy Miles
 
Node Boot Camp
Troy Miles
 
AWS Lambda Function with Kotlin
Troy Miles
 
React Native One Day
Troy Miles
 
React Native Evening
Troy Miles
 
Intro to React
Troy Miles
 
React Development with the MERN Stack
Troy Miles
 
Angular Application Testing
Troy Miles
 
ReactJS.NET
Troy Miles
 
What is Angular version 4?
Troy Miles
 
Angular Weekend
Troy Miles
 
From MEAN to the MERN Stack
Troy Miles
 
Functional Programming in JavaScript
Troy Miles
 
Functional Programming in Clojure
Troy Miles
 
MEAN Stack Warm-up
Troy Miles
 
The JavaScript You Wished You Knew
Troy Miles
 
Game Design and Development Workshop Day 1
Troy Miles
 
Build a Game in 60 minutes
Troy Miles
 
Quick & Dirty & MEAN
Troy Miles
 
A Quick Intro to ReactiveX
Troy Miles
 
Ad

Recently uploaded (20)

PDF
Market Insight : ETH Dominance Returns
CIFDAQ
 
PDF
A Strategic Analysis of the MVNO Wave in Emerging Markets.pdf
IPLOOK Networks
 
PDF
How ETL Control Logic Keeps Your Pipelines Safe and Reliable.pdf
Stryv Solutions Pvt. Ltd.
 
PDF
TrustArc Webinar - Navigating Data Privacy in LATAM: Laws, Trends, and Compli...
TrustArc
 
PPTX
Agile Chennai 18-19 July 2025 Ideathon | AI Powered Microfinance Literacy Gui...
AgileNetwork
 
PPTX
What-is-the-World-Wide-Web -- Introduction
tonifi9488
 
PDF
The Future of Mobile Is Context-Aware—Are You Ready?
iProgrammer Solutions Private Limited
 
PPTX
Introduction to Flutter by Ayush Desai.pptx
ayushdesai204
 
PPTX
Agile Chennai 18-19 July 2025 | Emerging patterns in Agentic AI by Bharani Su...
AgileNetwork
 
PDF
Structs to JSON: How Go Powers REST APIs
Emily Achieng
 
PDF
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
PDF
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
PDF
Economic Impact of Data Centres to the Malaysian Economy
flintglobalapac
 
PDF
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
PDF
Per Axbom: The spectacular lies of maps
Nexer Digital
 
PPTX
Agentic AI in Healthcare Driving the Next Wave of Digital Transformation
danielle hunter
 
PPTX
Dev Dives: Automate, test, and deploy in one place—with Unified Developer Exp...
AndreeaTom
 
PDF
Responsible AI and AI Ethics - By Sylvester Ebhonu
Sylvester Ebhonu
 
PDF
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
PPTX
IT Runs Better with ThousandEyes AI-driven Assurance
ThousandEyes
 
Market Insight : ETH Dominance Returns
CIFDAQ
 
A Strategic Analysis of the MVNO Wave in Emerging Markets.pdf
IPLOOK Networks
 
How ETL Control Logic Keeps Your Pipelines Safe and Reliable.pdf
Stryv Solutions Pvt. Ltd.
 
TrustArc Webinar - Navigating Data Privacy in LATAM: Laws, Trends, and Compli...
TrustArc
 
Agile Chennai 18-19 July 2025 Ideathon | AI Powered Microfinance Literacy Gui...
AgileNetwork
 
What-is-the-World-Wide-Web -- Introduction
tonifi9488
 
The Future of Mobile Is Context-Aware—Are You Ready?
iProgrammer Solutions Private Limited
 
Introduction to Flutter by Ayush Desai.pptx
ayushdesai204
 
Agile Chennai 18-19 July 2025 | Emerging patterns in Agentic AI by Bharani Su...
AgileNetwork
 
Structs to JSON: How Go Powers REST APIs
Emily Achieng
 
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
Economic Impact of Data Centres to the Malaysian Economy
flintglobalapac
 
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
Per Axbom: The spectacular lies of maps
Nexer Digital
 
Agentic AI in Healthcare Driving the Next Wave of Digital Transformation
danielle hunter
 
Dev Dives: Automate, test, and deploy in one place—with Unified Developer Exp...
AndreeaTom
 
Responsible AI and AI Ethics - By Sylvester Ebhonu
Sylvester Ebhonu
 
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
IT Runs Better with ThousandEyes AI-driven Assurance
ThousandEyes
 

5 Quick JavaScript Performance Improvement Tips

  • 3. The Rock n Coder • http://therockncoder.blogspot.com • http://www.youtube.com/user/rockncoder • https://github.com/Rockncoder • http://www.slideshare.net/rockncoder
  • 4. Our Agenda • Why Performance Matters • 5 Performance Tips • Resources • Summary
  • 6. Why Performance Matters? • 47% of consumers expect a 2 second page load • 40% abandon a page that takes 3 seconds or more to load • A 1 second delay in page response can result in a 7% reduction in conversions
  • 7. If an e-commerce site is making $100,000 a day in sales, a 1 second page delay could potentially cost you $2.5 million in lost sales every year
  • 8. We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil.Yet we should not pass up our opportunities in that critical 3%. D. Knuth
  • 10. Tip #5 Use as few files as possible
  • 11. Use as few files as possible • Browser can load multiple files at a time • But only one JS file at a time • Concatenate multiple JS file into one • Compress JS files • Prefer JS at the bottom of the HTML file
  • 12. Tip #4 Prefer local variables
  • 13. Prefer local variables • Variables in scope found quicker • JS search local scope, then global • with creates a new scope level ahead of local • closures also create new scope level
  • 15. Prefer local variables • Property chains similar to var scoping • Objects closer in the chain found quicker
  • 17. Tip #3 Reduce the work done in loops
  • 18. Reduce the work done in loops • No real speed difference between: for, while and do_while • Avoid for_in • (Watch library based for_each)
  • 19. Tip #2 Watch your plugins
  • 20. Watch your plugins • Know what your plugins do • Be sure to evaluate different plugins • Example jQuery.js or Zepto.js
  • 23. Avoid the DOM • The DOM is REALLY Slow • Avoid accessing it when possible • Do work offline then update DOM
  • 26. Resources • Microsoft Ajax Minifier
 http://ajaxmin.codeplex.com/ • Google Closure Tools
 https://developers.google.com/closure/ • Yahoo YSlow
 http://developer.yahoo.com/yslow/
  • 27. Books • High Performance JavaScript
 Nicholas C. Zakas • JavaScript Ninja
 John Resig & Bear Bibeaults • JavaScript: The Good Parts
 Douglas Crockford

  • 29. Summary • Avoid the DOM • Watch your plugins • Reduce the work done in loops • Prefer local variables • Use as few files as possible
  • 30. The Rock n Coder • http://therockncoder.blogspot.com • http://www.youtube.com/user/rockncoder • https://github.com/Rockncoder • http://www.slideshare.net/rockncoder