Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Performance em jQuery Apps
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Davidson Fellipe
April 24, 2012
Programming
200
2
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Performance em jQuery Apps
Davidson Fellipe
April 24, 2012
Transcript
38 slides
performance em jQuery apps por davidson fellipe
sobre mim • técnico em eletrônica • engenheiro da computação
pela upe • desenvolvedor na globo.com • quase mestrando em informática na puc-rio • @davidsonfellipe
por que melhorar a performance?
redução de bytes redução de requests reduzir o trabalho que
o browser tem de fazer
não use jQuery, ao menos que ele seja necessário
...pois alguns metodos podem ser mais faceis do que você
imagina size: function() {return this.length;},
$('a').bind(‘click’, function(){ console.log('elemento clicado: ' + $(this).attr('id')); }); $('a').bind(‘click’, function(){
console.log('elemento clicado: ' + this.id); });
por que usar a última versão?
um problema por usar versão antiga...
um problema por usar versão antiga...
operações por segundo
operações por segundo
teste! teste! teste! antes de fazer a migração
...mas evite linkar para última versão <script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
combine, minifique e gzipping seus scripts
Tente compactar todos os script em apenas 1 arquivo YUI
Compressor Muitos browsers não estão aptos a processar mais que 1 script paralelamente
comparativo entre performance de seletores
comparativo entre performance de seletores
evite o seletor universal $(“.box > *”) $(“.box”).children()
evite o seletor universal implicito $(“.box :radio”) $(“.box *:radio”) $(“.box
input:radio”)
1) $parent.find(‘.child’).show(); //+ rapida 2) $(‘.child", $parent).show(); //~5-10% + lenta
3) $('.child', $('#parent')).show(); //~23% + lenta 4) $parent.children(".child’).show(); //~50% + lenta 5) $(‘#parent > .child’).show(); //~70% + lenta 6) $(‘#parent .child’).show(); //~77% + lenta http://jsperf.com/jquery-selectors-context/2 formas de seleção
console.time console.timeEnd
evite manipulações desnecessárias do DOM
for( i = 0; i < 5000; i++){ $("body").css("background-color", "#f00");
$("body").addClass("fonte-maior"); } //acesso ao DOM várias vezes: 197ms var $body = $("body"); for( i = 0; i < 5000; i++){ $body.css("background-color", "#f00"); $body.addClass("fonte-maior"); } //cacheando o seletor: 158ms
use encadeamento
var $body = $("body"); for(i=0;i<10000;i++){ $body.css("background-color", "#f00"); $body.addClass("fonte-maior"); } //sem
chaining: 325ms var $body = $("body"); for(i=0;i<10000;i++){ $body.css("background-color", "#f00").addClass("fonte-maior"); } //com chaining: 308ms
Use contexto em seus seletores
var $contexto = $(".feed"); for(i=0;i<10000;i++){ $(".materia-titulo", $contexto).css("background-color", "#f00"); } //com
contexto: 1883ms for(i=0;i<10000;i++){ $(".materia-titulo").css("background-color", "#f00"); } //sem contexto: 2381ms
Use For ao invés de Each
Use id ao invés de classes
use cache fellipe.com/slides/jqueryfn
entenda o código-fonte do jQuery http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.js
None
None
None
None
performance x legibilidade
obrigado! • @davidsonfellipe • www.fellipe.com • github.com/davidsonfellipe • www.slideshare.net/davidsonfellipe •
outros sites: fellipe ou davidsonfellipe
More Decks by Davidson Fellipe
See All by Davidson Fellipe
Adventures from Enzyme to React Testing Library
fellipe
1
420
O melhor da monitoração de web performance
fellipe
0
490
Guia do Front-end das galáxias
fellipe
3
300
Workflow para desenvolvimento web e mobile usando gruntjs
fellipe
2
180
Como é trabalhar na Globo.com?
fellipe
3
140
Guia prático de desenvolvimento front-end para django devs
fellipe
1
200
Practical guide for front-end development for Django Devs
fellipe
0
150
Esse cara é o Grunt
fellipe
9
900
It's Javascript Time
fellipe
6
580
Other Decks in Programming
See All in Programming
Distance field of Julia set
kinakomoti321
0
340
Datadog を OTel にするメリットを考察する — Datadog との併用を実アプリで確かめる / Examining the Benefits of Moving Datadog to OTel — Testing OTel Alongside Datadog in a Real App
seike460
PRO
1
120
vue-tsc x TypeScript7
koukimiura
0
110
Scalaの型でマルチテナントの認可を守る
nextbeatdev
0
180
ローカルLLMの基本と近況 2611 / Local LLM basics and recent situation 2611
kishida
3
680
高速開発を止めずに 性能を上げる Flyleのシステム刷新と改善の歴史
azihsoyn
0
110
Rails初心者がパスキーを実装してみて大変だったこと
ktombow
0
250
AppFunctionsの内部実装を紐解く
hiroaki404
1
130
Promiseの向こう側へコンテキストを届ける ― proposal-async-context
seriseri
0
1.1k
protojson における文字化けの扱い
kazuki1023
0
470
Crash Auto Pipelines
veronikapj
1
460
느린 네트워크와 저사양 디바이스 사용자를 위한 웹뷰 로딩 시간 개선기
kmkim
1
290
Featured
See All Featured
Code Review Best Practice
trishagee
74
20k
RailsConf 2023
tenderlove
30
1.6k
Docker and Python
trallard
47
4.3k
What’s in a name? Adding method to the madness
productmarketing
PRO
24
4.3k
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
1
890
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
3k
Context Engineering - Making Every Token Count
addyosmani
9
1.3k
Practical Orchestrator
shlominoach
192
12k
Collaborative Software Design: How to facilitate domain modelling decisions
baasie
1
390
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
1
630
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
790
Heart Work Chapter 1 - Part 1
lfama
PRO
11
37k