Resource loading, prioritization, HTTP/2 - oh my!
Patrick Meenan
@PatMeenan
Key Performance Drivers of the HTML Parser
Rendering
• Incrementally paints
• Nothing to display until the parser reaches the <body>
• MUCH later for client-rendered DOM
Parser stops for (non-async) <script…> until:
• All previous CSS has been downloaded/processed
• The script code has been downloaded, parsed and
executed
Parser does NOT pause for:
• CSS loading
• Image Loading
Resources can only be loaded when discovered:
• Preload scanner finds resources in markup
• CSS, scripts, images
• Fonts and background images discovered during layout
• document.write discovered at write time
Optimal Ordering (for the user)
Render-blocking resources first
• CSS/Scripts in order needed, using 100% of bandwidth
• Fonts
Optimal Ordering (for the user)
Parser-blocking next
• Blocking scripts in order, using 100% of bandwidth
Optimal Ordering (for the user)
Async user-facing resources
• Visible images
• Async/defer scripts
• Non-visible images
Optimal Ordering (for the user)
Async non-user resources last
• Tracking/remarketing pixels
• Analytics
HTTP Prioritization
https://docs.google.com/document/d/1bCDuq9H1ih9iNjgzyAL0gpwNFiEP4TZS-YLRp_RuMlc/edit?usp=sharing
Priority Hints
https://developers.google.com/web/updates/2019/02/priority-hints
<ul class="carousel">
<li><img src="img/carousel-1.jpg" importance="high"></li>
<li><img src="img/carousel-2.jpg" importance="low"></li>
<li><img src="img/carousel-3.jpg" importance="low"></li>
<li><img src="img/carousel-4.jpg" importance="low"></li>
</ul>
Preloading
LayoutFonts
<link rel="preload" href="//www.i.cdn.cnn.com/.a/fonts/cnn/3.7.2/cnnsans-
regular.woff2" as="font" type="font/woff2" crossorigin="anonymous">
HTTP/2 Prioritization
HTTP/2
HTTP/1.x
https://twitter.com/AndyDavies/status/1060558550492155909
Preload/Appcache Chrome Bugs
Preloaded Fonts Block CSS
(blocking render)
https://andydavies.me/blog/2019/02/12/preloading-fonts-and-the-puzzle-of-priorities/
Prioritizing across connections
Prioritizing across connections
BBR vs CUBIC/RENO
https://labs.ripe.net/Members/gih/bbr-tcp
Connection coalescing
Different host names share a HTTP/2 connection if:
• Certificate includes both hosts
• DNS lookup resolves to the same IP
Current Browser Implementations
Chrome
Firefox
Safari
Edge
¯_(ツ)_/¯
Server Support
External Fonts (before)
Same-origin fonts (wtf)
Start Render
Same-origin fonts (correct)
Start Render
https://twitter.com/zachleat/status/1055219667894259712
Server Support (in Practice)
https://Ishttp2fastyet.com
Server Support (in Practice)
https://Ishttp2fastyet.com
Testing/Throttling
https://calendar.perfplanet.com/2016/testing-with-realistic-networking-conditions/
Server-initiated prioritization
Recommendations
• Test your HTTP/2 production deployment
• Stop Sharding
• Minimize 3rd-party resources early in load
• Use priority hints
• Hide non-critical resources (maybe)
Thank You!
@PatMeenan

Resource loading, prioritization, HTTP/2 - oh my!