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
Davidson Fellipe
April 24, 2012
Programming
190
2
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Performance em jQuery Apps
Davidson Fellipe
April 24, 2012
More Decks by Davidson Fellipe
See All by Davidson Fellipe
Adventures from Enzyme to React Testing Library
fellipe
1
400
O melhor da monitoração de web performance
fellipe
0
480
Guia do Front-end das galáxias
fellipe
3
290
Workflow para desenvolvimento web e mobile usando gruntjs
fellipe
2
170
Como é trabalhar na Globo.com?
fellipe
3
130
Guia prático de desenvolvimento front-end para django devs
fellipe
1
190
Practical guide for front-end development for Django Devs
fellipe
0
130
Esse cara é o Grunt
fellipe
9
880
It's Javascript Time
fellipe
6
550
Other Decks in Programming
See All in Programming
Vibes Containers 〜AIで変わるコンテナ設計と運用〜
tkikuc
3
520
アクセシビリティから考える情報設計
high_g_engineer
0
350
モバイル交通系ICへのチャージ実例から考える、クロスプラットフォーム開発におけるiOS実機テスト設計とCI運用
yusuga
1
260
市販E-Readerを乗っ取れ 〜Embedded Swiftで電子ペーパーガジェットを制御する〜
trickart
0
150
The Good Stuff, Not the Slop: Engineering High-Quality Android Apps with Modern AI Tooling
danybony
1
230
業務時間外もAIに働いてもらう話
colorful12
3
10k
XHTMLが残したもの
yosuke_furukawa
PRO
2
620
From 6 People Classroom Meetup to 100 People Regional Conference / FOSS4G Hiroshima 2026
furukawayasuto
0
130
『寄り添うラジオ』をAIで作る 体験価値から逆算した、会話しないUXと品質設計
theoriatec2024
3
140
Webの地図
yosuke_furukawa
PRO
4
3.8k
AIとGame Jamで、ゲームを完成させた話
takahirosaeki
0
110
Swift愛好会100回記念 第1回を振り返る
jollyjoester
0
120
Featured
See All Featured
We Are The Robots
honzajavorek
0
360
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
3k
SEO Brein meetup: CTRL+C is not how to scale international SEO
lindahogenes
1
2.9k
Digital Ethics as a Driver of Design Innovation
axbom
PRO
1
420
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
35
2.6k
Making the Leap to Tech Lead
cromwellryan
135
10k
Designing Experiences People Love
moore
143
24k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
56
3.5k
Designing for Performance
lara
611
70k
sira's awesome portfolio website redesign presentation
elsirapls
0
410
How to Align SEO within the Product Triangle To Get Buy-In & Support - #RIMC
aleyda
2
1.8k
Exploring the relationship between traditional SERPs and Gen AI search
raygrieselhuber
PRO
2
4.3k
Transcript
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