-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfaster-web.html
389 lines (325 loc) · 14.3 KB
/
faster-web.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
<!DOCTYPE html>
<!--[if lt IE 7]> <html class="no-js ie6" lang="en"> <![endif]-->
<!--[if IE 7]> <html class="no-js ie7" lang="en"> <![endif]-->
<!--[if IE 8]> <html class="no-js ie8" lang="en"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en"> <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Faster Websites</title>
<meta name="description" content="Optimizing web applications for more responsiveness">
<meta name="author" content="Mahmoud Said (aka modsaid)">
<meta name="viewport" content="width=1024, user-scalable=no">
<!-- Core and extension CSS files -->
<link rel="stylesheet" href="deck.js/core/deck.core.css">
<link rel="stylesheet" href="deck.js/extensions/goto/deck.goto.css">
<link rel="stylesheet" href="deck.js/extensions/menu/deck.menu.css">
<link rel="stylesheet" href="deck.js/extensions/navigation/deck.navigation.css">
<link rel="stylesheet" href="deck.js/extensions/status/deck.status.css">
<link rel="stylesheet" href="deck.js/extensions/hash/deck.hash.css">
<link rel="stylesheet" href="deck.js/extensions/scale/deck.scale.css">
<link rel="stylesheet" href="faster-web.css">
<!-- Style theme. More available in /themes/style/ or create your own. -->
<link rel="stylesheet" href="deck.js/themes/style/web-2.0.css">
<!-- Transition theme. More available in /themes/transition/ or create your own. -->
<link rel="stylesheet" href="deck.js/themes/transition/horizontal-slide.css">
<script src="deck.js/modernizr.custom.js"></script>
<link href="prettify.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="prettify.js"></script>
</head>
<body class="deck-container">
<!-- Begin slides -->
<section class="slide" id="title-slide">
<h1>Faster Websites</h1>
</section>
<section class="slide" id="outline">
<h2>Outline</h2>
<ul>
<li>Performance concepts</li>
<li>Responsiveness</li>
<li>Request lifecycle</li>
<li>Network Optimization</li>
<li>Javascript</li>
<li>CSS</li>
<li>Tools & References</li>
</ul>
</section>
<section class="slide" id="performance-concepts">
<h2>Performance Concepts</h2>
<ul>
<li class="slide" id="premature-optimization"><i>"Premature Optimization is the root of all evil" </i> <br/>Donald Knuth</li>
<li class="slide" id="concepts-tradeoff"> Tradeoffs
<ul>
<li>I want to go to heaven, but I don’t want to die.</li>
<li>Project Triangle: Fast. Good. Cheap. Pick Two.</li>
</ul>
</li>
<li class="slide" id="concepts-module"> Tune the significat parts first <br/>
<table style="width:700px; border: solid 1px">
<tr><th>Module</th><td>A</td><td>B</td><td>C</td><td>D</td></tr>
<tr><th>Cost</th><td>60%</td><td>4%</td><td>24%</td><td>12%</td></tr>
</table>
</li>
</ul>
</section>
<section class="slide" id="responsiveness">
<h2>Responsiveness</h2>
<ul>
<li class="slide" id="responsiveness-direct"><b>0.1 sec:</b> Direct manipulation of objects <span><img class="inline" src="images/happy-tears.jpg" /></span></li>
<li class="slide" id="responsiveness-working"><b>1 sec:</b> The machine is working <img class="inline" src="images/bored.jpg" /></li>
<li class="slide" id="responsiveness-max-attention"><b>10 sec:</b> Limit for keeping attention <img class="inline" src="images/annoyed.png" /></li>
<li class="slide" id="responsiveness-3aboko"><b>more than 10 sec:</b> <img class="inline" src="images/3aboko.jpg" /></li>
</ul>
</section>
<section class="slide" id="axe-of-error">
<h2>The Axes of Error</h2>
<p><img src="images/axe-of-failure.png"/></p>
</section>
<section class="slide" id="request-life-cycle">
<h2>Request life cycle</h2>
<p>
<img src="images/request-lifecycle.png" />
</p>
</section>
<section class="slide" id="akhbarak-case-initial-request">
<h2>Test Case: Akhbarak.net</h2>
<p>
<a href="http://www.webpagetest.org/result/120531_9F_8BY/1/details/" target="_blank"><img src="images/akhbarak-init-waterfall.png"></a>
</p>
</section>
<section class="slide" id="max-connections-per-domain">
<h2>Max concurrent downloads per domain</h2>
<p>
Browsers have a limit on the number of connections they open to a single hostname.
<img src="images/browsers-conn.png">
</p>
</section>
<section class="slide" id="max-connections-per-domain2">
<h2>Max concurrent downloads per domain</h2>
<ul>
<li> http://static.akhbarak.net</li>
<li> http://assets1.akhbarak.net</li>
<li> http://assets2.akhbarak.net</li>
<li> http://assets3.akhbarak.net</li>
</ul>
</section>
<section class="slide" id="caching-headers">
<h2>Use caching headers</h2>
<p> Static resources rarely changes. cache them
<pre><code class="prettyprint">
<%= image_tag("asa7be.png") %>
=> '/images/asa7be.png?1338397202'
<%= javascript_include_tag "plugins" %>
=> '/javascripts/plugins.js?1335678209'
<%= stylesheet_link_tag "style" %>
=> '/stylesheets/style.css?1554367479'</code></pre>
</p>
</section>
<section class="slide" id="caching-headers2">
<h2>Use caching headers</h2>
<p> configure expire headers in nginx
<pre><code class="prettyprint">
location ~* (stylesheets|javascripts|images) {
if (!-f $request_filename) {
break;
}
if ($query_string ~* "^[0-9]{10}$") {
expires max;
}
}</code></pre>
</p>
</section>
<section class="slide" id="akhbarak-case-second-request">
<h2>Test Case: Akhbarak.net, 2nd request</h2>
<p>
<a href="http://www.webpagetest.org/result/120531_9F_8BY/1/details/cached/" target="_blank"><img src="images/akhbarak-cached-waterfall.png"></a>
</p>
</section>
<section class="slide" id="javascript">
<h1>Javascript</h1>
</section>
<section class="slide" id="javascript-split-payload">
<h2>Splitting the payload</h2>
<ul>
<li>Include <strong>ONLY</strong> what is necessary for rendering, postpone everything else till later</li>
<li>Load the rest of the javascript in asynchronous manner</li>
<li>Lazy initialize</li>
<li>Avoid evaluating unnecessary scripts</li>
<li>Avoid evaluating duplicate scripts</li>
<li>Efficient JS</li>
</ul>
</section>
<section class="slide" id="javascript-async">
<h2>Load javascript asyncronously</h2>
<ul>
<li>XHR Eval</li>
<li>XHR Injection</li>
<li>Script in Iframe</li>
<li>Script DOM Element</li>
<li>Script Defer</li>
<li>document.write Script Tag</li>
</ul>
</section>
<section class="slide" id="javascript-async-xhr">
<h2>XHR Eval</h2>
<pre><code class="prettyprint">xhrObj = new XMLHttpRequest();
xhrObj.onreadystatechange =
function() {
if ( xhrObj.readyState == 4 && 200 == xhrObj.status ) {
eval(xhrObj.responseText);
}
};
xhrObj.open('GET', 'A.js', true); // must be same domain
xhrObj.send('');</code></pre>
</section>
<section class="slide" id="javascript-async-script-dom">
<h2>script DOM Element</h2>
<pre><code class="prettyprint">var scriptElem = document.createElement('script');
scriptElem.src = 'http://anydomain.com/A.js';
document.getElementsByTagName('head')[0].appendChild(scriptElem);</code></pre>
</section>
<section class="slide" id="javascript-async-defer">
<h2>script Defer (IE)</h2>
<p>Internet Explorer supports the SCRIPT DEFER attribute </p>
<pre><code class="prettyprint">< script defer src="A.js" >< /script ></code></pre>
</section>
<section class="slide" id="fb-sdk">
<h2>Facebook Async SDK</h2>
<pre><code class="prettyprint">< div id="fb-root" >< /div >
< script >(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/all.js#xfbml=1&appId=102269883223064";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));< /script ></code></pre>
</section>
<section class="slide" id="javascript-lazy-initialize">
<h2>Lazily initialize exessive event handlers</h2>
<ul>
<li>Example: 37signals <a href="http://37signals.com/svn/posts/3137-using-event-capturing-to-improve-basecamp-page-load-times" target="_blank">Using event capturing to improve Basecamp page load times</a></li>
<li>lots of todo lists and todo list items that needs to be sortable and draggable</li>
</ul>
<pre><code class="prettyprint">$.ready(function() {
$("article.todolist, section.todolists").sortable();
});</code></pre>
</section>
<section class="slide" id="javascript-lazy-initialize2">
<h2>Lazily initialize exessive event handlers (2)</h2>
<ul>
<li>Differ initialization until clear intention of usage</li>
<li>Differ initialization until the first mousedown event</li>
</ul>
<div class="slide" id='lazy-init-code'>
<pre><code class="prettyprint">$(document).on("mousedown", ".sortable_handle", function() {
$("article.todolist, section.todolists").sortable();
});</code></pre>
</div>
<div class="slide" id='basecamp-gain'>
<img src="images/basecamp-improvement.png" width="600">
</div>
</section>
<section class="slide" id="css">
<h1>CSS</h1>
</section>
<section class="slide" id="css-points">
<h2>CSS</h2>
<ul>
<li>Avoiding inefficient key selectors that match large numbers of elements can speed up page rendering.</li>
<li>Selectors are evaluated from right to left.</li>
<li>It is mainly about matching.</li>
<li>Remove unused rules/selectors</li>
</ul>
</section>
<section class="slide" id="css-selectors-type">
<h2>Types of Selectors</h2>
<p>ID's are the most efficient, Universal are the least</p>
<pre><code class="prettyprint">#main-navigation { } /* ID (Fastest) */
body.home #page-wrap { } /* ID */
.main-navigation { } /* Class */
ul li a.current { } /* Class *
ul { } /* Tag */
ul li a { } /* Tag */
* { } /* Universal (Slowest) */
#content [title='home'] /* Universal */</code></pre>
<pre><code class="prettyprint">#main-nav > li { } /* Slower than it might seem */
html body ul li a { } /* freaking disaster!!! */</code></pre>
</section>
<section class="slide" id="css-dont-import">
<h2>Avoid using @import</h2>
<div>
<pre><code class="prettyprint">< style >
@import url('a.css');
@import url('b.css');
< /style ></code></pre>
<IMG SRC="images/import-ok.gif">
</div>
<div class="slide" id="link-import">
<pre><code class="prettyprint">< link rel='stylesheet' type='text/css' href='a.css' >
< style > @import url('b.css'); < /style ></code></pre>
<IMG SRC="images/import-link.gif">
</div>
</section>
<section class="slide" id="tools">
<h2>Tools</h2>
<ul>
<li><a href="http://www.webpagetest.org/" target="_blank">http://www.webpagetest.org/</a></li>
<li><a href="http://unused-css.com/detect-unused-css" target="_blank">http://unused-css.com/detect-unused-css</a></li>
<li><a href="https://addons.mozilla.org/en-US/firefox/addon/dust-me-selectors/" target="_blank">Dust me Selectors (Firefox extension)</a></li>
<li><a href="https://addons.mozilla.org/en-US/firefox/addon/yslow/?src=search" target="_blank">YSlow (Firefox extension)</a></li>
</ul>
</section>
<section class="slide" id="references">
<h2>References</h2>
<ul>
<li><a href="http://my.safaribooksonline.com/book/web-design-and-development/9780596803773" target="_blank">Even Faster Websites</a></li>
<li><a href="http://developer.yahoo.com/performance/rules.html#dns_lookups" target="_blank">http://developer.yahoo.com/performance/rules.html#dns_lookups</a></li>
<li><a href="http://www.agileweboperations.com/lifecycle-of-a-click-improving-web-page-speed" target="_blank">http://www.agileweboperations.com/lifecycle-of-a-click-improving-web-page-speed</a></li>
<li><a href="https://developers.google.com/speed/docs/best-practices/rendering#UseEfficientCSSSelectors" target="_blank">https://developers.google.com/speed/docs/best-practices/rendering#UseEfficientCSSSelectors</a></li>
<li><a href="https://developer.mozilla.org/en/Writing_Efficient_CSS#ID_rules" target="_blank">https://developer.mozilla.org/en/Writing_Efficient_CSS#ID_rules</a></li>
<li><a href="http://css-tricks.com/efficiently-rendering-css/" target="_blank">http://css-tricks.com/efficiently-rendering-css/</a></li>
<li><a href="http://37signals.com/svn/posts/3137-using-event-capturing-to-improve-basecamp-page-load-times" target="_blank">http://37signals.com/svn/posts/3137-using-event-capturing-to-improve-basecamp-page-load-times</a></li>
<li><a href="http://taligarsiel.com/Projects/howbrowserswork1.htm#CSS_parsing " target="_blank">http://taligarsiel.com/Projects/howbrowserswork1.htm#CSS_parsing </a></li>
</ul>
</section>
<section class="slide" id="thankyou">
<h1>Thank You</h1>
</section>
<!-- deck.navigation snippet -->
<a href="#" class="deck-prev-link" title="Previous">←</a>
<a href="#" class="deck-next-link" title="Next">→</a>
<!-- deck.status snippet -->
<p class="deck-status">
<span class="deck-status-current"></span>
/
<span class="deck-status-total"></span>
</p>
<!-- deck.goto snippet -->
<form action="." method="get" class="goto-form">
<label for="goto-slide">Go to slide:</label>
<input type="text" name="slidenum" id="goto-slide" list="goto-datalist">
<datalist id="goto-datalist"></datalist>
<input type="submit" value="Go">
</form>
<!-- deck.hash snippet -->
<a href="." title="Permalink to this slide" class="deck-permalink">#</a>
<!-- Grab CDN jQuery, with a protocol relative URL; fall back to local if offline -->
<script src="//ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.min.js"></script>
<script>window.jQuery || document.write('<script src="deck.js/jquery-1.7.min.js"><\/script>')</script>
<!-- Deck Core and extensions -->
<script src="deck.js/core/deck.core.js"></script>
<script src="deck.js/extensions/hash/deck.hash.js"></script>
<script src="deck.js/extensions/menu/deck.menu.js"></script>
<script src="deck.js/extensions/goto/deck.goto.js"></script>
<script src="deck.js/extensions/status/deck.status.js"></script>
<script src="deck.js/extensions/navigation/deck.navigation.js"></script>
<script src="deck.js/extensions/scale/deck.scale.js"></script>
<!-- Initialize the deck -->
<script>
$(function() {
$.deck('.slide');
prettyPrint();
});
</script>
</body>
</html>