Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
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
470
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
生成AI導入の「期待外れ」を乗り越える ー 開発フロー改革が目指す、真の組織変革
starfish719
0
3.9k
【SRE NEXT 2026 Lunch Session】一人目専任SREの立ち上げを加速する ― AIと進めたオンボーディングで2分を0.04秒にした話
pkshadeck
PRO
0
3.5k
Lean は証明の正しさを確認するためだけのツールって思ってませんか?
inoueasei
1
140
2年かけて Deno に DOMMatrix を実装した話 / How I implemented DOMMatrix in Deno over two years
petamoriken
0
200
OpenSpecのproposalにbrainstormingを持たせてみた
tigertora7571
1
200
GDG Korea Android: 2026 I/O Extended ~ What's new in Android development tools
pluu
0
210
メールのエイリアス機能を履き違えない
isshinfunada
0
220
Laravel Boostに学ぶ、AIにPHPを書かせる技術 〜OSSの実装から蒸留するエージェント制御の王道〜
kentaroutakeda
3
660
壊れたパーサから始める関数型設計と構成的なパーサ #fp_matsuri
raiga0310
2
440
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
520
AI Engineeringは、AIプロダクトだけのものか? 〜AIがソフトウェアを作る時代の新しい当たり前〜 / No AI in your product. AI Engineering in your development.
rkaga
4
360
PHPだって関数型したい 〜できること、できないこと〜 / fp-in-php
jsoizo
1
270
Featured
See All Featured
What the history of the web can teach us about the future of AI
inesmontani
PRO
1
650
Discover your Explorer Soul
emna__ayadi
2
1.2k
AI: The stuff that nobody shows you
jnunemaker
PRO
9
870
Imperfection Machines: The Place of Print at Facebook
scottboms
270
14k
Test your architecture with Archunit
thirion
1
2.3k
Believing is Seeing
oripsolob
1
180
SEO Brein meetup: CTRL+C is not how to scale international SEO
lindahogenes
1
2.8k
The Illustrated Children's Guide to Kubernetes
chrisshort
51
53k
Beyond borders and beyond the search box: How to win the global "messy middle" with AI-driven SEO
davidcarrasco
3
200
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
162
16k
A Modern Web Designer's Workflow
chriscoyier
698
190k
Dominate Local Search Results - an insider guide to GBP, reviews, and Local SEO
greggifford
PRO
0
250
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