SlideShare uma empresa Scribd logo
1 de 99
A ROUGH GUIDE to



JavaScript
Performance
                   by Mark Perkins, July 2010
A *rough* guide....
A *rough* guide....


General principles for you to take and build
on
A *rough* guide....


General principles for you to take and build
on

3 tips for loadtime performance
A *rough* guide....


General principles for you to take and build
on

3 tips for loadtime performance

3 principles for speedy runtimes
A *rough* guide....


General principles for you to take and build
on

3 tips for loadtime performance

3 principles for speedy runtimes

Seconds, not milliseconds (possibly...)
We’re NOT going to cover (much...)
We’re NOT going to cover (much...)


General frontend performance topics
We’re NOT going to cover (much...)


General frontend performance topics

Crazy language optimisations eg.
~~( 1*‘12.34’ )
We’re NOT going to cover (much...)


General frontend performance topics

Crazy language optimisations eg.
~~( 1*‘12.34’ )

Advanced testing tools
LOADTIME
Steve Souders
“Only 10-20% of
                       the end user
                       response time is
                       spent downloading
                       the HTML
                       document.

                       The other
                       80-90% is spent



           ’ Golden Rule
Steve Souders
Some facts of life
Some facts of life


HTTP requests are expensive
Some facts of life


HTTP requests are expensive

Browsers are single threaded (ignoring
web workers)
Some facts of life


HTTP requests are expensive

Browsers are single threaded (ignoring
web workers)

2-4 resources downloaded in parallel per
host
Some facts of life


HTTP requests are expensive

Browsers are single threaded (ignoring
web workers)

2-4 resources downloaded in parallel per
host

<script> tags disable parallel downloads
and block all rendering below them
JS 1

       JS 2


                     IMAGE 1


                     IMAGE 2

              time
<script>




1. Move <script> tags to the bottom (of the
page)
FOUJC!!
2. Concatenate, Minimise, GZip
Concatenation
Concatenation


Less HTTP requests === :-)
Concatenation


Less HTTP requests === :-)

But... rarely used scripts may be better off
loaded where appropriate.
Concatenation


Less HTTP requests === :-)

But... rarely used scripts may be better off
loaded where appropriate.

Automate: Sprockets, php-sprockets etc
Minification
Minification


Strips whitespace and comments out,
shortens variables in functions
Minification


Strips whitespace and comments out,
shortens variables in functions

Minify, don’t Pack!
Minification


Strips whitespace and comments out,
shortens variables in functions

Minify, don’t Pack!

Anything that obfuscates code and requires
eval’ing has a performance hit. Avoid!
GZip your JS!
GZip your JS!


GZip is the way forward. Use it.
GZip your JS!


GZip is the way forward. Use it.

Can reduce file size by up to 70%
GZip your JS!


GZip is the way forward. Use it.

Can reduce file size by up to 70%

No whitespace removal or variable alteration
- easy to debug
GZip your JS!


GZip is the way forward. Use it.

Can reduce file size by up to 70%

No whitespace removal or variable alteration
- easy to debug

Configure once and forget about it, all taken
care of by the server
GZip your JS!


GZip is the way forward. Use it.

Can reduce file size by up to 70%

No whitespace removal or variable alteration
- easy to debug

Configure once and forget about it, all taken
care of by the server
3. Load scripts in a non-blocking
               way
Dynamic scripts
Dynamic scripts


Add <script> tags via DOM methods to
avoid blocking of other page processes
Dynamic scripts


Add <script> tags via DOM methods to
avoid blocking of other page processes

Only FF and Opera guarantee execution
order (concatenation can help with this)
Dynamic scripts


Add <script> tags via DOM methods to
avoid blocking of other page processes

Only FF and Opera guarantee execution
order (concatenation can help with this)

Use onload callbacks to tell us when it’s
loaded, can nest to ensure execution order
is respected
A little help from your friends...
A little help from your friends...


Lazy Loader: http://github.com/rgrove/
lazyload/
A little help from your friends...


Lazy Loader: http://github.com/rgrove/
lazyload/

LabJS: http://labjs.com
A little help from your friends...


Lazy Loader: http://github.com/rgrove/
lazyload/

LabJS: http://labjs.com
Loadtime recap!
Loadtime recap!


1. Move <script> tags to the bottom of the
page
Loadtime recap!


1. Move <script> tags to the bottom of the
page

2. Concatenate, Minimise, GZip
Loadtime recap!


1. Move <script> tags to the bottom of the
page

2. Concatenate, Minimise, GZip

3. Load scripts in a non-blocking way
RUNTIME
1. Be afraid of the DOM!
About that DOM...
About that DOM...


The DOM is a language independent API for
working with XML/HTML documents.
About that DOM...


The DOM is a language independent API for
working with XML/HTML documents.

The JS engine and the DOM are implemented
separately in browsers.
About that DOM...


The DOM is a language independent API for
working with XML/HTML documents.

The JS engine and the DOM are implemented
separately in browsers.

Every time you touch the DOM you incur a
performance penalty.
Big DOM: Scary!



                  Little DOM:
                  Not so scary.
Keep bridge crossings to a minimum!




                       DOM-LAND




JAVASCRIPT-
   VILLE
‘Cache’ your DOM
selection results for re-use
Minimise this kind of DOM
insertion wherever possible
Event Delegation FTW!
2. Write lazy code
Lazy code does as little work as
possible, without repetition
Lazy code does as little work as
possible, without repetition
Lazy code does as little work as
possible, without repetition
Lazy code does as little work as
possible, without repetition
Lazy code does as little work as
possible, without repetition
3. Keep your Ajax under control
Caching is King!!
Caching is King!!


Use GET requests
Caching is King!!


Use GET requests

Tailor URLs to the user where possible:
Caching is King!!


Use GET requests

Tailor URLs to the user where possible:
http://mydomain/ajax/info.php?
user_id=129473
Caching is King!!


Use GET requests

Tailor URLs to the user where possible:
http://mydomain/ajax/info.php?
user_id=129473

Ensure appropriate headers are sent by the
server
Caching is King!!


Use GET requests

Tailor URLs to the user where possible:
http://mydomain/ajax/info.php?
user_id=129473

Ensure appropriate headers are sent by the
server
(ie. a far future Expires header)
Caching is King!!


Use GET requests

Tailor URLs to the user where possible:
http://mydomain/ajax/info.php?
user_id=129473

Ensure appropriate headers are sent by the
server
(ie. a far future Expires header)
Be smart about return data
Be smart about return data


HTML > JSONP > JSON > XML
Be smart about return data


HTML > JSONP > JSON > XML

Return HTML wherever possible - templating
in JS is slow, your server is fast, use it!
Be smart about return data


HTML > JSONP > JSON > XML

Return HTML wherever possible - templating
in JS is slow, your server is fast, use it!

JSONP - no parse time, already in a native
format
Be smart about return data


HTML > JSONP > JSON > XML

Return HTML wherever possible - templating
in JS is slow, your server is fast, use it!

JSONP - no parse time, already in a native
format

JSON - needs parsing/evaluating first
Be smart about return data


HTML > JSONP > JSON > XML

Return HTML wherever possible - templating
in JS is slow, your server is fast, use it!

JSONP - no parse time, already in a native
format

JSON - needs parsing/evaluating first
Runtime recap!
Runtime recap!


1. Be afraid of the DOM
Runtime recap!


1. Be afraid of the DOM

2. Write lazy code
Runtime recap!


1. Be afraid of the DOM

2. Write lazy code

3. Keep your Ajax under control
Additional Resources

Books:

High Performance Websites: http://amzn.to/bbBTln
Even Faster Websites: http://amzn.to/a7iJmo
High Performance JavaScript: http://amzn.to/9CgsfA
JavaScript Rocks! http://javascriptrocks.com/performance/

Interwebs:

Steve Souders HPWS blog: http://stevesouders.com/
Yahoo Exceptional Performance resources: http://developer.yahoo.com/
performance/
YUI blog (performance category): http://yuiblog.com/blog/category/
performance
Understanding site load waterfalls: http://bit.ly/9KkmN1
Nokia JS Performance best practices: http://bit.ly/aYLXLU
Velocity Conference: http://en.oreilly.com/velocity2010
My ‘performance’ tag on Delicious: http://delicious.com/allmarkedup/
performance

Mais conteúdo relacionado

Mais procurados

The Future of library dependency management of Ruby
 The Future of library dependency management of Ruby The Future of library dependency management of Ruby
The Future of library dependency management of RubyHiroshi SHIBATA
 
44CON London 2015 - Going AUTH the Rails on a Crazy Train
44CON London 2015 - Going AUTH the Rails on a Crazy Train44CON London 2015 - Going AUTH the Rails on a Crazy Train
44CON London 2015 - Going AUTH the Rails on a Crazy Train44CON
 
HipHop VM: overclocking Symfony
HipHop VM: overclocking SymfonyHipHop VM: overclocking Symfony
HipHop VM: overclocking SymfonyVadim Borodavko
 
ApacheCon 2014 - What's New in Apache httpd 2.4
ApacheCon 2014 - What's New in Apache httpd 2.4ApacheCon 2014 - What's New in Apache httpd 2.4
ApacheCon 2014 - What's New in Apache httpd 2.4Jim Jagielski
 
Northeast PHP - High Performance PHP
Northeast PHP - High Performance PHPNortheast PHP - High Performance PHP
Northeast PHP - High Performance PHPJonathan Klein
 
Scaling PHP to 40 Million Uniques
Scaling PHP to 40 Million UniquesScaling PHP to 40 Million Uniques
Scaling PHP to 40 Million UniquesJonathan Klein
 
Jruby a Pi and a database
Jruby a Pi and a databaseJruby a Pi and a database
Jruby a Pi and a databasePhilipp Fehre
 
Fast, concurrent ruby web applications with EventMachine and EM::Synchrony
Fast, concurrent ruby web applications with EventMachine and EM::SynchronyFast, concurrent ruby web applications with EventMachine and EM::Synchrony
Fast, concurrent ruby web applications with EventMachine and EM::SynchronyKyle Drake
 
Test::Kantan - Perl and Testing
Test::Kantan - Perl and TestingTest::Kantan - Perl and Testing
Test::Kantan - Perl and TestingTokuhiro Matsuno
 
Plack perl superglue for web frameworks and servers
Plack perl superglue for web frameworks and serversPlack perl superglue for web frameworks and servers
Plack perl superglue for web frameworks and serversTatsuhiko Miyagawa
 
Distributed Queue System using Gearman
Distributed Queue System using GearmanDistributed Queue System using Gearman
Distributed Queue System using GearmanEric Cho
 
Productive web applications that run only on the frontend
Productive web applications that run only on the frontendProductive web applications that run only on the frontend
Productive web applications that run only on the frontendStefan Adolf
 
Building reusable components with generics and protocols
Building reusable components with generics and protocolsBuilding reusable components with generics and protocols
Building reusable components with generics and protocolsDonny Wals
 
SydPHP March 2012 Meetup
SydPHP March 2012 MeetupSydPHP March 2012 Meetup
SydPHP March 2012 MeetupGraham Weldon
 

Mais procurados (19)

The Future of library dependency management of Ruby
 The Future of library dependency management of Ruby The Future of library dependency management of Ruby
The Future of library dependency management of Ruby
 
44CON London 2015 - Going AUTH the Rails on a Crazy Train
44CON London 2015 - Going AUTH the Rails on a Crazy Train44CON London 2015 - Going AUTH the Rails on a Crazy Train
44CON London 2015 - Going AUTH the Rails on a Crazy Train
 
HipHop VM: overclocking Symfony
HipHop VM: overclocking SymfonyHipHop VM: overclocking Symfony
HipHop VM: overclocking Symfony
 
Perl6 meets JVM
Perl6 meets JVMPerl6 meets JVM
Perl6 meets JVM
 
ApacheCon 2014 - What's New in Apache httpd 2.4
ApacheCon 2014 - What's New in Apache httpd 2.4ApacheCon 2014 - What's New in Apache httpd 2.4
ApacheCon 2014 - What's New in Apache httpd 2.4
 
WASM! WASI! WAGI! WAT?
WASM! WASI! WAGI! WAT?WASM! WASI! WAGI! WAT?
WASM! WASI! WAGI! WAT?
 
Northeast PHP - High Performance PHP
Northeast PHP - High Performance PHPNortheast PHP - High Performance PHP
Northeast PHP - High Performance PHP
 
Scaling PHP to 40 Million Uniques
Scaling PHP to 40 Million UniquesScaling PHP to 40 Million Uniques
Scaling PHP to 40 Million Uniques
 
Serverless Rust
Serverless RustServerless Rust
Serverless Rust
 
Devignition 2011
Devignition 2011Devignition 2011
Devignition 2011
 
Jruby a Pi and a database
Jruby a Pi and a databaseJruby a Pi and a database
Jruby a Pi and a database
 
Fast, concurrent ruby web applications with EventMachine and EM::Synchrony
Fast, concurrent ruby web applications with EventMachine and EM::SynchronyFast, concurrent ruby web applications with EventMachine and EM::Synchrony
Fast, concurrent ruby web applications with EventMachine and EM::Synchrony
 
Test::Kantan - Perl and Testing
Test::Kantan - Perl and TestingTest::Kantan - Perl and Testing
Test::Kantan - Perl and Testing
 
Plack perl superglue for web frameworks and servers
Plack perl superglue for web frameworks and serversPlack perl superglue for web frameworks and servers
Plack perl superglue for web frameworks and servers
 
Distributed Queue System using Gearman
Distributed Queue System using GearmanDistributed Queue System using Gearman
Distributed Queue System using Gearman
 
What's new in RubyGems3
What's new in RubyGems3What's new in RubyGems3
What's new in RubyGems3
 
Productive web applications that run only on the frontend
Productive web applications that run only on the frontendProductive web applications that run only on the frontend
Productive web applications that run only on the frontend
 
Building reusable components with generics and protocols
Building reusable components with generics and protocolsBuilding reusable components with generics and protocols
Building reusable components with generics and protocols
 
SydPHP March 2012 Meetup
SydPHP March 2012 MeetupSydPHP March 2012 Meetup
SydPHP March 2012 Meetup
 

Destaque

How to create a blog
How to create a blogHow to create a blog
How to create a blogHuda Shubair
 
10 j som una nació nosaltres decidim gràcies!
10 j som una nació nosaltres decidim   gràcies!10 j som una nació nosaltres decidim   gràcies!
10 j som una nació nosaltres decidim gràcies!CDC Dreta Eixample
 
Whmis safety training 2
Whmis safety training 2Whmis safety training 2
Whmis safety training 2jjayne
 
Myori流ストレス回避術
Myori流ストレス回避術Myori流ストレス回避術
Myori流ストレス回避術moyori
 
New media Revolution
New media RevolutionNew media Revolution
New media RevolutionHuda Shubair
 
Whmis safety training 3
Whmis safety training 3Whmis safety training 3
Whmis safety training 3jjayne
 
11 building an electric circuit
11 building an electric circuit11 building an electric circuit
11 building an electric circuitmrtangextrahelp
 
Check it Out! (Respect)
Check it Out!  (Respect)Check it Out!  (Respect)
Check it Out! (Respect)Judy Cannedy
 
Chris mc cann_presentation
Chris mc cann_presentationChris mc cann_presentation
Chris mc cann_presentationInfluence People
 
Botanicals Bamboo Leaf 01a
Botanicals Bamboo Leaf 01aBotanicals Bamboo Leaf 01a
Botanicals Bamboo Leaf 01aEileen TOGASHI
 

Destaque (17)

How to create a blog
How to create a blogHow to create a blog
How to create a blog
 
10 j som una nació nosaltres decidim gràcies!
10 j som una nació nosaltres decidim   gràcies!10 j som una nació nosaltres decidim   gràcies!
10 j som una nació nosaltres decidim gràcies!
 
bagsplanet
bagsplanetbagsplanet
bagsplanet
 
New media rev
New media revNew media rev
New media rev
 
Whmis safety training 2
Whmis safety training 2Whmis safety training 2
Whmis safety training 2
 
Myori流ストレス回避術
Myori流ストレス回避術Myori流ストレス回避術
Myori流ストレス回避術
 
New media rev
New media revNew media rev
New media rev
 
New media Revolution
New media RevolutionNew media Revolution
New media Revolution
 
Whmis safety training 3
Whmis safety training 3Whmis safety training 3
Whmis safety training 3
 
Jornadas2
Jornadas2Jornadas2
Jornadas2
 
11 building an electric circuit
11 building an electric circuit11 building an electric circuit
11 building an electric circuit
 
prueba
pruebaprueba
prueba
 
Ch10 final
Ch10 finalCh10 final
Ch10 final
 
Check it Out! (Respect)
Check it Out!  (Respect)Check it Out!  (Respect)
Check it Out! (Respect)
 
Chris mc cann_presentation
Chris mc cann_presentationChris mc cann_presentation
Chris mc cann_presentation
 
Orris aster court premier
Orris aster court premierOrris aster court premier
Orris aster court premier
 
Botanicals Bamboo Leaf 01a
Botanicals Bamboo Leaf 01aBotanicals Bamboo Leaf 01a
Botanicals Bamboo Leaf 01a
 

Semelhante a A rough guide to JavaScript Performance

Site Performance - From Pinto to Ferrari
Site Performance - From Pinto to FerrariSite Performance - From Pinto to Ferrari
Site Performance - From Pinto to FerrariJoseph Scott
 
Client Side Performance @ Xero
Client Side Performance @ XeroClient Side Performance @ Xero
Client Side Performance @ XeroCraig Walker
 
The Mysteries Of JavaScript-Fu (@media SF Edition)
The Mysteries Of JavaScript-Fu (@media SF Edition)The Mysteries Of JavaScript-Fu (@media SF Edition)
The Mysteries Of JavaScript-Fu (@media SF Edition)danwrong
 
Rails Presentation (Anton Dmitriyev)
Rails Presentation (Anton Dmitriyev)Rails Presentation (Anton Dmitriyev)
Rails Presentation (Anton Dmitriyev)True-Vision
 
Killing the Angle Bracket
Killing the Angle BracketKilling the Angle Bracket
Killing the Angle Bracketjnewmanux
 
Practical Performance Tips and Tricks to Make Your HTML/JavaScript Apps Faster
Practical Performance Tips and Tricks to Make Your HTML/JavaScript Apps FasterPractical Performance Tips and Tricks to Make Your HTML/JavaScript Apps Faster
Practical Performance Tips and Tricks to Make Your HTML/JavaScript Apps FasterDoris Chen
 
Web Performance, Scalability, and Testing Techniques - Boston PHP Meetup
Web Performance, Scalability, and Testing Techniques - Boston PHP MeetupWeb Performance, Scalability, and Testing Techniques - Boston PHP Meetup
Web Performance, Scalability, and Testing Techniques - Boston PHP MeetupJonathan Klein
 
Frontend Performance: Illusions & browser rendering
Frontend Performance: Illusions & browser renderingFrontend Performance: Illusions & browser rendering
Frontend Performance: Illusions & browser renderingManuel Garcia
 
Tuning web performance
Tuning web performanceTuning web performance
Tuning web performanceGeorge Ang
 
Tuning Web Performance
Tuning Web PerformanceTuning Web Performance
Tuning Web PerformanceEric ShangKuan
 
Going on an HTTP Diet: Front-End Web Performance
Going on an HTTP Diet: Front-End Web PerformanceGoing on an HTTP Diet: Front-End Web Performance
Going on an HTTP Diet: Front-End Web PerformanceAdam Norwood
 
Martin Splitt "A short history of the web"
Martin Splitt "A short history of the web"Martin Splitt "A short history of the web"
Martin Splitt "A short history of the web"Fwdays
 
The Mysteries Of JavaScript-Fu (RailsConf Ediition)
The Mysteries Of JavaScript-Fu (RailsConf Ediition)The Mysteries Of JavaScript-Fu (RailsConf Ediition)
The Mysteries Of JavaScript-Fu (RailsConf Ediition)danwrong
 
SD, a P2P bug tracking system
SD, a P2P bug tracking systemSD, a P2P bug tracking system
SD, a P2P bug tracking systemJesse Vincent
 
In Pursuit of the Holy Grail: Building Isomorphic JavaScript Apps
In Pursuit of the Holy Grail: Building Isomorphic JavaScript AppsIn Pursuit of the Holy Grail: Building Isomorphic JavaScript Apps
In Pursuit of the Holy Grail: Building Isomorphic JavaScript AppsSpike Brehm
 
Socket applications
Socket applicationsSocket applications
Socket applicationsJoão Moura
 
Let's contribute, HTML5Rocks/ko!
Let's contribute, HTML5Rocks/ko!Let's contribute, HTML5Rocks/ko!
Let's contribute, HTML5Rocks/ko!Chang W. Doh
 
The Mysteries Of JavaScript-Fu (@media Europe Edition)
The Mysteries Of JavaScript-Fu (@media Europe Edition)The Mysteries Of JavaScript-Fu (@media Europe Edition)
The Mysteries Of JavaScript-Fu (@media Europe Edition)danwrong
 
HTTP cache @ PUG Rome 03-29-2011
HTTP cache @ PUG Rome 03-29-2011HTTP cache @ PUG Rome 03-29-2011
HTTP cache @ PUG Rome 03-29-2011Alessandro Nadalin
 

Semelhante a A rough guide to JavaScript Performance (20)

Site Performance - From Pinto to Ferrari
Site Performance - From Pinto to FerrariSite Performance - From Pinto to Ferrari
Site Performance - From Pinto to Ferrari
 
Client Side Performance @ Xero
Client Side Performance @ XeroClient Side Performance @ Xero
Client Side Performance @ Xero
 
The Mysteries Of JavaScript-Fu (@media SF Edition)
The Mysteries Of JavaScript-Fu (@media SF Edition)The Mysteries Of JavaScript-Fu (@media SF Edition)
The Mysteries Of JavaScript-Fu (@media SF Edition)
 
Rails Presentation (Anton Dmitriyev)
Rails Presentation (Anton Dmitriyev)Rails Presentation (Anton Dmitriyev)
Rails Presentation (Anton Dmitriyev)
 
Killing the Angle Bracket
Killing the Angle BracketKilling the Angle Bracket
Killing the Angle Bracket
 
Practical Performance Tips and Tricks to Make Your HTML/JavaScript Apps Faster
Practical Performance Tips and Tricks to Make Your HTML/JavaScript Apps FasterPractical Performance Tips and Tricks to Make Your HTML/JavaScript Apps Faster
Practical Performance Tips and Tricks to Make Your HTML/JavaScript Apps Faster
 
Mojolicious
MojoliciousMojolicious
Mojolicious
 
Web Performance, Scalability, and Testing Techniques - Boston PHP Meetup
Web Performance, Scalability, and Testing Techniques - Boston PHP MeetupWeb Performance, Scalability, and Testing Techniques - Boston PHP Meetup
Web Performance, Scalability, and Testing Techniques - Boston PHP Meetup
 
Frontend Performance: Illusions & browser rendering
Frontend Performance: Illusions & browser renderingFrontend Performance: Illusions & browser rendering
Frontend Performance: Illusions & browser rendering
 
Tuning web performance
Tuning web performanceTuning web performance
Tuning web performance
 
Tuning Web Performance
Tuning Web PerformanceTuning Web Performance
Tuning Web Performance
 
Going on an HTTP Diet: Front-End Web Performance
Going on an HTTP Diet: Front-End Web PerformanceGoing on an HTTP Diet: Front-End Web Performance
Going on an HTTP Diet: Front-End Web Performance
 
Martin Splitt "A short history of the web"
Martin Splitt "A short history of the web"Martin Splitt "A short history of the web"
Martin Splitt "A short history of the web"
 
The Mysteries Of JavaScript-Fu (RailsConf Ediition)
The Mysteries Of JavaScript-Fu (RailsConf Ediition)The Mysteries Of JavaScript-Fu (RailsConf Ediition)
The Mysteries Of JavaScript-Fu (RailsConf Ediition)
 
SD, a P2P bug tracking system
SD, a P2P bug tracking systemSD, a P2P bug tracking system
SD, a P2P bug tracking system
 
In Pursuit of the Holy Grail: Building Isomorphic JavaScript Apps
In Pursuit of the Holy Grail: Building Isomorphic JavaScript AppsIn Pursuit of the Holy Grail: Building Isomorphic JavaScript Apps
In Pursuit of the Holy Grail: Building Isomorphic JavaScript Apps
 
Socket applications
Socket applicationsSocket applications
Socket applications
 
Let's contribute, HTML5Rocks/ko!
Let's contribute, HTML5Rocks/ko!Let's contribute, HTML5Rocks/ko!
Let's contribute, HTML5Rocks/ko!
 
The Mysteries Of JavaScript-Fu (@media Europe Edition)
The Mysteries Of JavaScript-Fu (@media Europe Edition)The Mysteries Of JavaScript-Fu (@media Europe Edition)
The Mysteries Of JavaScript-Fu (@media Europe Edition)
 
HTTP cache @ PUG Rome 03-29-2011
HTTP cache @ PUG Rome 03-29-2011HTTP cache @ PUG Rome 03-29-2011
HTTP cache @ PUG Rome 03-29-2011
 

Último

Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 

Último (20)

Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 

A rough guide to JavaScript Performance

  • 1. A ROUGH GUIDE to JavaScript Performance by Mark Perkins, July 2010
  • 3. A *rough* guide.... General principles for you to take and build on
  • 4. A *rough* guide.... General principles for you to take and build on 3 tips for loadtime performance
  • 5. A *rough* guide.... General principles for you to take and build on 3 tips for loadtime performance 3 principles for speedy runtimes
  • 6. A *rough* guide.... General principles for you to take and build on 3 tips for loadtime performance 3 principles for speedy runtimes Seconds, not milliseconds (possibly...)
  • 7. We’re NOT going to cover (much...)
  • 8. We’re NOT going to cover (much...) General frontend performance topics
  • 9. We’re NOT going to cover (much...) General frontend performance topics Crazy language optimisations eg. ~~( 1*‘12.34’ )
  • 10. We’re NOT going to cover (much...) General frontend performance topics Crazy language optimisations eg. ~~( 1*‘12.34’ ) Advanced testing tools
  • 11.
  • 12.
  • 13.
  • 16. “Only 10-20% of the end user response time is spent downloading the HTML document. The other 80-90% is spent ’ Golden Rule Steve Souders
  • 18. Some facts of life HTTP requests are expensive
  • 19. Some facts of life HTTP requests are expensive Browsers are single threaded (ignoring web workers)
  • 20. Some facts of life HTTP requests are expensive Browsers are single threaded (ignoring web workers) 2-4 resources downloaded in parallel per host
  • 21. Some facts of life HTTP requests are expensive Browsers are single threaded (ignoring web workers) 2-4 resources downloaded in parallel per host <script> tags disable parallel downloads and block all rendering below them
  • 22. JS 1 JS 2 IMAGE 1 IMAGE 2 time
  • 23. <script> 1. Move <script> tags to the bottom (of the page)
  • 24.
  • 25.
  • 26.
  • 28.
  • 29.
  • 33. Concatenation Less HTTP requests === :-) But... rarely used scripts may be better off loaded where appropriate.
  • 34. Concatenation Less HTTP requests === :-) But... rarely used scripts may be better off loaded where appropriate. Automate: Sprockets, php-sprockets etc
  • 36. Minification Strips whitespace and comments out, shortens variables in functions
  • 37. Minification Strips whitespace and comments out, shortens variables in functions Minify, don’t Pack!
  • 38. Minification Strips whitespace and comments out, shortens variables in functions Minify, don’t Pack! Anything that obfuscates code and requires eval’ing has a performance hit. Avoid!
  • 40. GZip your JS! GZip is the way forward. Use it.
  • 41. GZip your JS! GZip is the way forward. Use it. Can reduce file size by up to 70%
  • 42. GZip your JS! GZip is the way forward. Use it. Can reduce file size by up to 70% No whitespace removal or variable alteration - easy to debug
  • 43. GZip your JS! GZip is the way forward. Use it. Can reduce file size by up to 70% No whitespace removal or variable alteration - easy to debug Configure once and forget about it, all taken care of by the server
  • 44. GZip your JS! GZip is the way forward. Use it. Can reduce file size by up to 70% No whitespace removal or variable alteration - easy to debug Configure once and forget about it, all taken care of by the server
  • 45. 3. Load scripts in a non-blocking way
  • 46.
  • 48. Dynamic scripts Add <script> tags via DOM methods to avoid blocking of other page processes
  • 49. Dynamic scripts Add <script> tags via DOM methods to avoid blocking of other page processes Only FF and Opera guarantee execution order (concatenation can help with this)
  • 50. Dynamic scripts Add <script> tags via DOM methods to avoid blocking of other page processes Only FF and Opera guarantee execution order (concatenation can help with this) Use onload callbacks to tell us when it’s loaded, can nest to ensure execution order is respected
  • 51.
  • 52.
  • 53. A little help from your friends...
  • 54. A little help from your friends... Lazy Loader: http://github.com/rgrove/ lazyload/
  • 55. A little help from your friends... Lazy Loader: http://github.com/rgrove/ lazyload/ LabJS: http://labjs.com
  • 56. A little help from your friends... Lazy Loader: http://github.com/rgrove/ lazyload/ LabJS: http://labjs.com
  • 58. Loadtime recap! 1. Move <script> tags to the bottom of the page
  • 59. Loadtime recap! 1. Move <script> tags to the bottom of the page 2. Concatenate, Minimise, GZip
  • 60. Loadtime recap! 1. Move <script> tags to the bottom of the page 2. Concatenate, Minimise, GZip 3. Load scripts in a non-blocking way
  • 62. 1. Be afraid of the DOM!
  • 64. About that DOM... The DOM is a language independent API for working with XML/HTML documents.
  • 65. About that DOM... The DOM is a language independent API for working with XML/HTML documents. The JS engine and the DOM are implemented separately in browsers.
  • 66. About that DOM... The DOM is a language independent API for working with XML/HTML documents. The JS engine and the DOM are implemented separately in browsers. Every time you touch the DOM you incur a performance penalty.
  • 67. Big DOM: Scary! Little DOM: Not so scary.
  • 68. Keep bridge crossings to a minimum! DOM-LAND JAVASCRIPT- VILLE
  • 69.
  • 70. ‘Cache’ your DOM selection results for re-use
  • 71.
  • 72. Minimise this kind of DOM insertion wherever possible
  • 73.
  • 76. Lazy code does as little work as possible, without repetition
  • 77. Lazy code does as little work as possible, without repetition
  • 78. Lazy code does as little work as possible, without repetition
  • 79. Lazy code does as little work as possible, without repetition
  • 80. Lazy code does as little work as possible, without repetition
  • 81. 3. Keep your Ajax under control
  • 83. Caching is King!! Use GET requests
  • 84. Caching is King!! Use GET requests Tailor URLs to the user where possible:
  • 85. Caching is King!! Use GET requests Tailor URLs to the user where possible: http://mydomain/ajax/info.php? user_id=129473
  • 86. Caching is King!! Use GET requests Tailor URLs to the user where possible: http://mydomain/ajax/info.php? user_id=129473 Ensure appropriate headers are sent by the server
  • 87. Caching is King!! Use GET requests Tailor URLs to the user where possible: http://mydomain/ajax/info.php? user_id=129473 Ensure appropriate headers are sent by the server (ie. a far future Expires header)
  • 88. Caching is King!! Use GET requests Tailor URLs to the user where possible: http://mydomain/ajax/info.php? user_id=129473 Ensure appropriate headers are sent by the server (ie. a far future Expires header)
  • 89. Be smart about return data
  • 90. Be smart about return data HTML > JSONP > JSON > XML
  • 91. Be smart about return data HTML > JSONP > JSON > XML Return HTML wherever possible - templating in JS is slow, your server is fast, use it!
  • 92. Be smart about return data HTML > JSONP > JSON > XML Return HTML wherever possible - templating in JS is slow, your server is fast, use it! JSONP - no parse time, already in a native format
  • 93. Be smart about return data HTML > JSONP > JSON > XML Return HTML wherever possible - templating in JS is slow, your server is fast, use it! JSONP - no parse time, already in a native format JSON - needs parsing/evaluating first
  • 94. Be smart about return data HTML > JSONP > JSON > XML Return HTML wherever possible - templating in JS is slow, your server is fast, use it! JSONP - no parse time, already in a native format JSON - needs parsing/evaluating first
  • 96. Runtime recap! 1. Be afraid of the DOM
  • 97. Runtime recap! 1. Be afraid of the DOM 2. Write lazy code
  • 98. Runtime recap! 1. Be afraid of the DOM 2. Write lazy code 3. Keep your Ajax under control
  • 99. Additional Resources Books: High Performance Websites: http://amzn.to/bbBTln Even Faster Websites: http://amzn.to/a7iJmo High Performance JavaScript: http://amzn.to/9CgsfA JavaScript Rocks! http://javascriptrocks.com/performance/ Interwebs: Steve Souders HPWS blog: http://stevesouders.com/ Yahoo Exceptional Performance resources: http://developer.yahoo.com/ performance/ YUI blog (performance category): http://yuiblog.com/blog/category/ performance Understanding site load waterfalls: http://bit.ly/9KkmN1 Nokia JS Performance best practices: http://bit.ly/aYLXLU Velocity Conference: http://en.oreilly.com/velocity2010 My ‘performance’ tag on Delicious: http://delicious.com/allmarkedup/ performance

Notas do Editor