-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
379 lines (373 loc) · 12.4 KB
/
Copy pathindex.html
File metadata and controls
379 lines (373 loc) · 12.4 KB
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
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>Web Performance Part 1 - Caching</title>
<link rel="stylesheet" href="css/reveal.css">
<link rel="stylesheet" href="css/theme/black.css">
<!-- Theme used for syntax highlighting of code -->
<link rel="stylesheet" href="lib/css/zenburn.css">
<!-- Printing and PDF exports -->
<script>
var link = document.createElement( 'link' );
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = window.location.search.match( /print-pdf/gi ) ? 'css/print/pdf.css' : 'css/print/paper.css';
document.getElementsByTagName( 'head' )[0].appendChild( link );
</script>
</head>
<body>
<div class="reveal">
<div class="slides">
<section>
<section data-markdown>
<textarea data-template>
# Web Performance
### Part 2 - First Meaningful Paint
<br>
<br>
### Steve Reiter
Email: sreiter@dotdash.com
Slack: DevEdmonton / YegSec
</textarea>
</section>
<section data-markdown>
<textarea data-template>
## A little about me
<br>
- Senior Developer at Investopedia for 3 years
- Over 13 million unique monthly visitors
- ~14,000 active sessions at peak
- ~800,000,000 page views in 2017
</textarea>
</section>
<section data-markdown>
<textarea data-template>
<img data-src="images/dotdash.png" class="plain" style="background: none"><br>
- Online Publisher
- 7 Sites and growing
- ~115 million unique monthly visitors across all sites
- About 9x more traffic than Investopedia alone
</textarea>
</section>
</section>
<section>
<section data-markdown>
<textarea data-template>
## brief overview of a page load
</textarea>
</section>
<section data-markdown>
<textarea data-template>
## Step 1 - Get the Document
<br>
1. Browser sends domain to DNS service
2. DNS service returns an IP
3. Browser requests document from the web server at the IP
4. Web Server processes the request and returns the document
This is the same as when you go "View Source"
</textarea>
</section>
<section data-markdown>
<textarea data-template>
## Step 2 - Parse the document
*When the browser encounters a link, or script, tag; or a non-system font in css, it fetches each of these resources with the same steps.*
1. Browser sends domain to DNS service
2. DNS service returns an IP
3. Browser requests resource from the web server at the IP
4. Web Server processes the request and returns the resource
5. Browser processes the resource
</textarea>
</section>
<section data-markdown>
<textarea data-template>
## Example Resources
<br>
<pre><code><link rel="stylesheet" href="/styles/main.css?v=5.866" /></code></pre>
<pre><code><script src="/js/article.js?v=5.866"></script></code></pre>
<pre><code><img src="https://i.investopedia.com/public/fa/img/fg_fa_header_mobile.png"></code></pre>
</textarea>
</section>
</section>
<section>
<section data-markdown>
<textarea data-template>
## Round Trips are Expensive!
<img data-src="images/nanosecond.jpg"><br>
"One Nanosecond!" - Grace Hopper
</textarea>
</section>
<section data-markdown>
<textarea data-template>
### Edmonton -> North Virginia
Distance: ~ 3200 km<br>
Speed of light in Fibre: ~200,000,000 m/s<br>
Time: 16ms or 32ms for a round trip
</textarea>
</section>
<section data-markdown>
<textarea data-template>
- What about hops through routers?
- No straight line of fibre from Edm to N. Virginia
<br><br>
Actual latency is ~80ms.<br><br>
<br>
In 2 seconds we have time for 25 sequential round trips.
</textarea>
</section>
<section data-markdown>
### But what about
- TCP handshake (1 round trip)
- TLS negotiation (2 round trips)
- DNS fetch (1 round trip)
<br>
It will likely take 3-4 rounds trips for EACH resource...
</section>
<section data-markdown>
### So what should we focus on first?
1. Asynchronous fetching
2. Reduce the number of resources
3. Client side JS performance (If client side rendering)
</section>
<section data-markdown>
### These are also important
- More performant image formats
- Client side JS performance
- Reduce the size of resources
- Reduce the size of the document
</section>
</section>
<section>
<section data-markdown>
## Measuring Web Performance
</section>
<section data-markdown>
<textarea data-template>
- Time to First Byte (TTFB)
- Time to Last Byte (TTLB)
- First CPU Idle
- Time to Interactive
</textarea>
</section>
<section data-markdown>
<textarea data-template>
# First Meaningful Paint
<br>
- "When the primary content of the page is visible"
- Somewhat subjective
- But, really important for SEO and user experience
</textarea>
</section>
<section data-markdown>
<textarea data-template>
## Lighthouse
<br>
- Great at identifying what needs to be fixed first
- Limited device and bandwitch simulation
- Now built in to Chrome
</textarea>
</section>
<section data-markdown>
<textarea data-template>
## Webpagetest.org
<br>
- Test your site from specific locations
- Test your site from specific devices
- Highly detailed graphs
</textarea>
</section>
<section data-markdown>
<textarea data-template>
## Coverage
<br>
- Chrome dev tools
- Top right menu > More Tools > Coverage
- CSS and JS coverage on load
- VERY useful when identifying what CSS/JS is needed on page load
</textarea>
</section>
</section>
<section>
<section data-markdown>
## Making things asynchronous
</section>
<section data-markdown>
<textarea data-template>
Put some hints at the top of the document to help the browser out.<br><br>
</textarea>
</section>
<section data-markdown>
<textarea data-template>
### DNS Prefetch
<pre><code><link rel="dns-prefetch" href="//some-3rd-party.com"></code></pre>
</textarea>
</section>
<section data-markdown>
<textarea data-template>
### Preconnect
<pre><code><link rel="preconnect" href="http://some-3rd-party.com"></code></pre>
</textarea>
</section>
<section data-markdown>
<textarea data-template>
### Prefetch
<pre><code><link rel="prefetch" href="image.png"></code></pre>
<pre><code><link rel="prefetch" href="font.woff2"></code></pre>
<pre><code><link rel="prefetch" href="bitcoin-miner.js"></code></pre>
Anything that can be cached by the browser.
</textarea>
</section>
<section data-markdown>
<textarea data-template>
### async attribute
<pre><code><script src="/js/article.js?v=5.866" async></script></code></pre>
- This will cause the js to be downloaded asynchronously.
- Browser will pause parsing and execute *immediately* once it has the file.
</textarea>
</section>
<section data-markdown>
<textarea data-template>
### defer attribute
<pre><code><script src="/js/article.js?v=5.866" defer></script></code></pre>
- This will cause the js to be downloaded asynchronously but run syncronously in the order included on the page.
- The script will be executed *after* the document has been parsed but *before* the DOMContentLoaded event.
</textarea>
</section>
</section>
<section>
<section data-markdown>
<textarea data-template>
## Summary
- Load everything you can asynchronously
- Reduce the number of resources
- Load only the CSS and JS that you need
</textarea>
</section>
<section data-markdown>
<textarea data-template>
## But in Reality
</textarea>
</section>
<section data-markdown>
<textarea data-template>
When you have an existing site it's often not this simple.
</textarea>
</section>
<section data-markdown>
<textarea data-template>
You already have CSS and JS. Completely refactoring all of that might not be an option.
</textarea>
</section>
<section data-markdown>
<textarea data-template>
Remember: The primary goal should be to get a fast First Meaningful Paint and maybe First Interactive.
</textarea>
</section>
</section>
<section>
<section data-markdown>
<textarea data-template>
## Cheating
</textarea>
</section>
<section data-markdown>
<textarea data-template>
### Isolate Critical CSS
- Use the chrome coverage to identify CSS used on page load
- Move that CSS into a separate file
- Focus on "above the fold"
- Use HTTP/2 to push the critical CSS
</textarea>
</section>
<section data-markdown>
<textarea data-template>
### Defer remaining CSS
- loadCSS (https://github.com/filamentgroup/loadCSS/)
- Handles browser compatibility for you
- Swaps to the new style sheet once downloaded
</textarea>
</section>
<section data-markdown>
<textarea data-template>
### But...
- Our infrastructure doesn't support HTTP/2
- Other pages break when we pull the CSS out into separate files
- Our critical CSS is still 80% unused
</textarea>
</section>
<section data-markdown>
<textarea data-template>
### Inline the critical css
- On the backend, dump the critical CSS into the document
- This increase server response for us... but we have page caching
</textarea>
</section>
<section data-markdown>
<textarea data-template>
### Fixing other page
- Use webpack or grunt to combine the critical CSS file with the old CSS file
- critical-article.css + article.css = old-article.css
</textarea>
</section>
<section data-markdown>
<textarea data-template>
### further reducing size of critical css
<br>
<br>
¯\\\_(ツ)\_/¯
</textarea>
</section>
</section>
<section>
<section data-markdown>
<textarea data-template>
## More Cheating!
</textarea>
</section>
<section data-markdown>
<textarea data-template>
### Fonts
- Normally you can use a preload directive to loads your fonts early
- Google fonts API serves a CSS file that includes the font URLs
- The font URLs in that file will be different for each browser/OS combo
</textarea>
</section>
<section data-markdown>
<textarea data-template>
### Inline the font!
- Get the font file for the browser/OS most commonly seen on your site
- Edit the font to remove all the symbols you don't really use
- Base64 encode the slim font and inline it on the page
- Use loadCSS to swap to the full font once it's loaded
</textarea>
</section>
<section>
<section data-markdown>
<textarea data-template>
### Downside to cheating
- Wasting our users bandwidth
- Harder to maintain the codebase
- Removes an incentive to clean up the code
</textarea>
</section>
</section>
</div>
</div>
<script src="lib/js/head.min.js"></script>
<script src="js/reveal.js"></script>
<script>
// More info about config & dependencies:
// - https://github.com/hakimel/reveal.js#configuration
// - https://github.com/hakimel/reveal.js#dependencies
Reveal.initialize({
dependencies: [
{ src: 'plugin/markdown/marked.js' },
{ src: 'plugin/markdown/markdown.js' },
{ src: 'plugin/notes/notes.js', async: true },
{ src: 'plugin/highlight/highlight.js', async: true, callback: function() { hljs.initHighlightingOnLoad(); } }
]
});
</script>
</body>
</html>