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
140
Guia prático de desenvolvimento front-end para django devs
fellipe
1
190
Practical guide for front-end development for Django Devs
fellipe
0
140
Esse cara é o Grunt
fellipe
9
890
It's Javascript Time
fellipe
6
560
Other Decks in Programming
See All in Programming
Unity6 URPによる海底をテーマにしたVJシステムの解説 | Unity Shader 完全に理解した 勉強会
gam0022
0
340
AI時代のコードレビューは人に向けるな、仕組みに向けろ
texmeijin
5
3.5k
ソニーのクラウド共通基盤の変遷とAI時代の開発スタイルに合わせた進化 / The Journey of Sony’s Common Cloud Platform and Its Evolution for AI-Native Development
kenjiyoneyama
0
240
Are APIs Still Relevant in the AI Era?
soyuka
0
440
GemmaをJevのように使ってみる / Use Gemma like Jev
kishida
5
740
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
580
Kubernetes祭り #2 OP/ED
bells17
0
110
JRuby: Past, Present, and Future
headius
0
230
AIに “答え“を書かせるのを やめてみた
___akari11
0
110
sbt 2.0: takeoff
eed3si9n
0
110
【加筆修正版】Laravel のアプリケーションをどこにデプロイするか #phpcon_ehime
akase244
0
150
Rでドレミ/Do-Re-Mi_with_R
florets1
0
130
Featured
See All Featured
Getting science done with accelerated Python computing platforms
jacobtomlinson
2
520
Gemini Prompt Engineering: Practical Techniques for Tangible AI Outcomes
mfonobong
2
580
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
210
The Cost Of JavaScript in 2023
addyosmani
55
10k
Side Projects
sachag
456
43k
Measuring & Analyzing Core Web Vitals
bluesmoon
9
1k
Context Engineering - Making Every Token Count
addyosmani
9
1.2k
SEOcharity - Dark patterns in SEO and UX: How to avoid them and build a more ethical web
sarafernandez
0
300
Odyssey Design
rkendrick25
PRO
2
860
Done Done
chrislema
187
17k
What’s in a name? Adding method to the madness
productmarketing
PRO
24
4.2k
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
2
350
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