SlideShare a Scribd company logo
More Than You Ever Wanted
to Know About Resource Hints
Harry Roberts • @csswizardry
Hi, I’m Harry
Consultant Performance Engineer
Leeds, UK
csswizardry.com
@csswizardry
More Than You Ever Wanted to Know About Resource Hints - Harry Roberts (CSS Wizardry)
More Than You Ever Wanted to Know About Resource Hints - Harry Roberts (CSS Wizardry)
iPro-Tip / Short Summary
!Caveat / Warning / Bug
More Than You Ever Wanted to Know About Resource Hints - Harry Roberts (CSS Wizardry)
Resource Hints
“
“These primitives enable the developer […] to
assist the user agent in the decision process of
which origins it should connect to, and which
resources it should fetch and preprocess to
improve page performance.”
i
Single lines of HTML
that can dramatically
speed up your site
<head>
...
<link rel="preconnect" href="https://www.youtube.com/" />
<link rel="prefetch" href="app.ae72eb.js" />
<link rel="preload" href="/assets/webfont.woff2" as="font"
type="font/woff2" crossorigin />
...
</head>
csswz.it/rh
Overview
1.dns-prefetch
2.preconnect
3.prefetch
4.preload
5.subresource
6.prerender
dns-prefetch
csswz.it/dns-prefetch
i
Resolve the IP address
for a given domain
ahead of time
iWhen you know the
domain but not the URL
<link rel="dns-prefetch" href="https://youtube.com" />
More Than You Ever Wanted to Know About Resource Hints - Harry Roberts (CSS Wizardry)
154 <iframe
155 src="https://www.youtube.com/embed/5g8a9luSZVI"
156 width="560" height="315">
157 </iframe>
5g8a9luSZVI
DNS Lookup
216.58.198.110
“
“[…] common names […] can answer in closer to
80–120ms.  […] an uncommon name […] can
average closer to 200–300ms.”
— csswz.it/2GuZo21
“
“More interestingly, for any of these queries
that access the internet, dropped packets, and
overworked (under provisioned) name resolvers,
regularly increases the total resolution time to
between 1 and 10 seconds.”
— csswz.it/2GuZo21
@andydavies
!
dns-prefetch is
implemented as
prefetch in IE9…
preconnect
csswz.it/preconnect
i
Resolve the IP address
and open a TCP/TLS
connection for a given
domain ahead of time
iWhen you know the
domain but not the URL
<link rel="preconnect" href="https://fonts.googleapis.com" />
More Than You Ever Wanted to Know About Resource Hints - Harry Roberts (CSS Wizardry)
5g8a9luSZVI
TCP Handshake TLS Negotiation
hpbn.co
More Than You Ever Wanted to Know About Resource Hints - Harry Roberts (CSS Wizardry)
More Than You Ever Wanted to Know About Resource Hints - Harry Roberts (CSS Wizardry)
preconnect with

dns-prefetch fallback
<link rel="preconnect dns-prefetch" href="//twitter.com" />
!Breaks in Safari
More Than You Ever Wanted to Know About Resource Hints - Harry Roberts (CSS Wizardry)
@andydavies
<link rel="preconnect" href="https://twitter.com" />
<link rel="dns-prefetch" href="https://twitter.com" />
!Be judicious with
preconnect
Be Judicious
Only warm up frequent, significant, and likely origins
Don’t warm up fourth, fifth, sixth party origins
Opening many connections can have a CPU and battery cost
Chrome can only conduct six simultaneous DNS resolutions
!Firefucked
More Than You Ever Wanted to Know About Resource Hints - Harry Roberts (CSS Wizardry)
prefetch
csswz.it/prefetch
iA file needed for
subsequent navigation
<link rel="prefetch" href="/assets/video-player.js" />
More Than You Ever Wanted to Know About Resource Hints - Harry Roberts (CSS Wizardry)
More Than You Ever Wanted to Know About Resource Hints - Harry Roberts (CSS Wizardry)
More Than You Ever Wanted to Know About Resource Hints - Harry Roberts (CSS Wizardry)
<!-- search-results.html -->
<link rel="prefetch" href="/assets/video-player.js" />
i
Download the file and
drop it into HTTP cache
for later usage
“
“The user agent SHOULD NOT apply
preprocessing on the response and MUST
NOT automatically execute or apply it against
the current page context.”
<!-- search-results.html -->
<link rel="prefetch" href="/assets/video-player.js" />
<!-- video.html -->
<script src="/assets/video-player.js"></script>
Downloaded by this…
… executed by this.
Caching
prefetch will not execute or otherwise process the resource
It will drop it into HTTP cache as per its caching headers
Except…
“
“…those with the no-store Cache-
Control header. A resource will
be revalidated before use if there is
a Vary response header, no-cache Cache-
Control header, or if the resource is more than
five minutes old.”
— csswz.it/nostate-prefetch
iFetched with lowest
possible priority
i
In-flight prefetches
persist across
navigations
More Than You Ever Wanted to Know About Resource Hints - Harry Roberts (CSS Wizardry)
More Than You Ever Wanted to Know About Resource Hints - Harry Roberts (CSS Wizardry)
!…prefetch acts like
dns-prefetch in IE9
<link rel="prefetch"

href="https://code.jquery.com/jquery-3.4.0.js" />
preload
csswz.it/preload
i
A mandatory fetch for
a file needed for the
current navigation
iA way to surface late-
discovered resources
<link rel="preload" href="/assets/webfont.woff2"
as="font" type="font/woff2" crossorigin />
<link rel="preload" href="/assets/webfont.woff2"
as="font" type="font/woff2" crossorigin />
More Than You Ever Wanted to Know About Resource Hints - Harry Roberts (CSS Wizardry)
Late-discovered
resource?
HTML
CSS
Font
}
1000ms
HTML
CSS
Background
}
1250ms
HTML
CSS
Font
JS
VDOM
}
1350ms
preload helps the
browser find them sooner
<script src="assets/app.js"></script>
<link rel="preload" href="assets/app.css"
as="style" />
<link rel="preload" href="assets/font.woff2"
as="font" type="font/woff2" crossorigin />
HTML
CSS
Font
JS
VDOM
}
750ms
The as Attribute
<link rel="preload" href="/assets/webfont.woff2"
as="font" type="font/woff2" crossorigin />
"audio"
"document"
"embed"
"fetch"
"font"
as="image"
"object"
"script"
"style"
"track"
"video"
"worker"
“
“The attribute is necessary to guarantee correct
prioritization, request matching, application of
the correct CSP3 policy, and setting of the
appropriate Accept request header.”
More Than You Ever Wanted to Know About Resource Hints - Harry Roberts (CSS Wizardry)
!Don’t try to be sneaky
<link rel="preload" href="style.css" as="style" />
<link rel="preload" href="app.js" as="script" />
<link rel="preload" href="image.jpg" as="image" />
<link rel="preload" href="style.css" as="image" />
<link rel="preload" href="app.js" as="style" />
<link rel="preload" href="image.jpg" as="script" />
More Than You Ever Wanted to Know About Resource Hints - Harry Roberts (CSS Wizardry)
iPriority Hints will help
<link rel="preload" href="masthead.jpg"
as="image" importance="high" />
<link rel="preload" href="lazy.css"
as="style" importance="low" />
The type Attribute
<link rel="preload" href="hero.webp"
as="image" type="image/webp" />
The crossorigin Attribute
“
“Preload links for CORS enabled resources, such
as fonts or images with a crossorigin attribute,
must also include a crossorigin attribute, in
order for the resource to be properly used.”
iKeep an eye on Console
More Than You Ever Wanted to Know About Resource Hints - Harry Roberts (CSS Wizardry)
!Beware Google Chrome
Chrome Issues
Chrome over-prioritises preload
Dispatches preloads before other critical resources
Often returns less-critical resources sooner
@andydavies
@andydavies
0.4s slower to
start render
@andydavies
subresource
iPrecursor to preload…
!…but completely
deprecated.
<link rel="subresource" href="/assets/webfont.woff2" />
SUBRESOURCE
“
“…not useful, proprietary, and buggy.”
— Yoav Weiss, csswz.it/2VOEyQc
prerender
csswz.it/prerender
i
Download and build
entire webpages in the
background…
i…kinda…
i…it’s complicated.
More Than You Ever Wanted to Know About Resource Hints - Harry Roberts (CSS Wizardry)
<link rel="prerender" href="/login/" />
More Than You Ever Wanted to Know About Resource Hints - Harry Roberts (CSS Wizardry)
More Than You Ever Wanted to Know About Resource Hints - Harry Roberts (CSS Wizardry)
PRERENDER
Problematic Prerender
Huge memory footprint with rendering whole new pages
Bandwidth usage spikes for site and user
Register multiple analytics hits, ad impressions
How do we handle timers, HTTP auth, interstitials, autoplay media?
How do we handle animations? Do we expect the carousel to start
running? Or do we write more code to wait for page visibility?
What if we get MitM and are made to prerender a malicious page?
How would the user know? They wouldn’t!
Prerender is dead,

long live prerender!
Prerender is dead,

long live prerender!
NoState Prefetch
i
prerender is the API;
NoState Prefetch is the
mechanism
!prerender will not
render anything
!prerender will not
render anything
!
NoState Prefetch
iA recursive prefetch
A B
B1
B2
B3
B4
B5
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, minimum-scale=1.0" />
<title>Prerender</title>
<link rel="prerender" href="https://csswizardry.com" />
</head>
<body>
<h1>Prerender</h1>
</body>
</html>
iFetched with lowest
possible priority
More Than You Ever Wanted to Know About Resource Hints - Harry Roberts (CSS Wizardry)
Tips, Tricks, and Gotchas
iDeploy as HTTP
Headers
More Than You Ever Wanted to Know About Resource Hints - Harry Roberts (CSS Wizardry)
@andydavies
!
Edge only supports
HTTP header for
preconnect
!
Edge doesn’t support
HTTP header for
preload
iGenerate Dynamically
instant.page
More Than You Ever Wanted to Know About Resource Hints - Harry Roberts (CSS Wizardry)
!Have an escape hatch
if ($omgWeAreBeingDDoSed == false) {
<script src="https://instant.page/1.1.0" defer></script>
}
!You Need a Scheme
<link rel="preconnect" href="domain.com" />
==
<link rel="preconnect" href="./domain.com" />
<link rel="preconnect" href="https://domain.com" />
All Together!
Implementing Resource Hints
1.Identify a key page
2.Audit important assets and origins
3.Assess likely user flows
4.Design bespoke Resource Hint strategies
Web font
Likely next navigation
Critical third party
Web font Likely next navigation
Critical third party
JS image gallery
Resource Hint Strategy
1.HTTP header preconnect to cloudinary
2.Regular preconnect for other third parties
3.preload to discover web font sooner
4.prefetch for gallery.js
5.prerender or prefetch for likely next navigation
// HTTP response header
link: <https://res.cloudinary.com>; rel=preconnect
<!-- Preconnect other third party origins -->
<link rel="preconnect"
href="https://www.google-analytics.com">
<link rel="dns-prefetch"
href="https://www.google-analytics.com">
<!-- Early-discover web font -->
<link rel="stylesheet" href="/assets/app.css" />
<link rel="preload" href="/assets/webfont.woff2"
as="font" type="font/woff2" crossorigin />
<!-- Prefetch image gallery for next page -->
<link rel="prefetch" href="/assets/gallery.js" />
<!-- Prerender first three search results -->
<link rel="prerender" href="/products/one.html" />
<link rel="prerender" href="/products/two.html" />
<link rel="prerender" href="/products/three.html" />
<head>
<link rel="preconnect" href="https://www.google-analytics.com">
<link rel="dns-prefetch" href="https://www.google-analytics.com">
<link rel="stylesheet" href="/assets/app.css" />
<link rel="preload" href="/assets/webfont.woff2"
as="font" type="font/woff2" crossorigin />
<link rel="prefetch" href="/assets/gallery.js" />
<link rel="prerender" href="/products/one.html" />
<link rel="prerender" href="/products/two.html" />
<link rel="prerender" href="/products/three.html" />
</head>
<head>
<link rel="prefetch" href="/assets/product-01-large.jpg" />
<link rel="prefetch" href="/assets/product-02-large.jpg" />
<link rel="prefetch" href="/assets/product-03-large.jpg" />
</head>
Thank You!
@csswizardry
csswizardry@gmail.com
speakerdeck.com/csswizardry
harry.is/for-hire

More Related Content

PDF
HTML5 workshop, part 1
PDF
HTML5, The Open Web, and what it means for you - Altran
PDF
Walk on the Client Side - Chris Mountford
PPTX
The Need for Speed - SMX Sydney 2013
PDF
Real World Web Standards
PPTX
Nodejs.meetup
PDF
Building an HTML5 Video Player
PDF
[jqconatx] Adaptive Images for Responsive Web Design
HTML5 workshop, part 1
HTML5, The Open Web, and what it means for you - Altran
Walk on the Client Side - Chris Mountford
The Need for Speed - SMX Sydney 2013
Real World Web Standards
Nodejs.meetup
Building an HTML5 Video Player
[jqconatx] Adaptive Images for Responsive Web Design

Similar to More Than You Ever Wanted to Know About Resource Hints - Harry Roberts (CSS Wizardry) (20)

PPTX
Progressive downloads and rendering (Stoyan Stefanov)
PDF
Html5 - short intro
PDF
Progressive Downloads and Rendering
PDF
Progressive Web Apps
KEY
Deliverance talk at plone meetup
PPT
Please dont touch-3.6-jsday
PDF
Web Development for UX Designers
PDF
Web-Performance
PPTX
10 Tips to make your Website lightning-fast - SMX Stockholm 2012
PDF
Speak The Web: The HTML5 Experiments
PDF
Beyond Breakpoints: Improving Performance for Responsive Sites
PDF
Frontend for developers
KEY
Developing High Performance Web Apps - CodeMash 2011
PPTX
Diazo: Bridging Designers and Programmers
PDF
Seo Cheat Sheet
PDF
Seo cheat-sheet
PPT
Build Your Own CMS with Apache Sling
PPT
Responsive content
KEY
Taking your Web App for a walk
KEY
Theming websites effortlessly with Deliverance (CMSExpo 2010)
Progressive downloads and rendering (Stoyan Stefanov)
Html5 - short intro
Progressive Downloads and Rendering
Progressive Web Apps
Deliverance talk at plone meetup
Please dont touch-3.6-jsday
Web Development for UX Designers
Web-Performance
10 Tips to make your Website lightning-fast - SMX Stockholm 2012
Speak The Web: The HTML5 Experiments
Beyond Breakpoints: Improving Performance for Responsive Sites
Frontend for developers
Developing High Performance Web Apps - CodeMash 2011
Diazo: Bridging Designers and Programmers
Seo Cheat Sheet
Seo cheat-sheet
Build Your Own CMS with Apache Sling
Responsive content
Taking your Web App for a walk
Theming websites effortlessly with Deliverance (CMSExpo 2010)
Ad

More from Shift Conference (20)

PDF
Shift Remote: AI: How Does Face Recognition Work (ars futura)
PDF
Shift Remote: AI: Behind the scenes development in an AI company - Matija Ili...
PDF
Shift Remote: AI: Smarter AI with analytical graph databases - Victor Lee (Ti...
PDF
Shift Remote: DevOps: Devops with Azure Devops and Github - Juarez Junior (Mi...
PDF
Shift Remote: DevOps: Autodesks research into digital twins for AEC - Kean W...
PPTX
Shift Remote: DevOps: When metrics are not enough, and everyone is on-call - ...
PDF
Shift Remote: DevOps: Modern incident management with opsgenie - Kristijan L...
PDF
Shift Remote: DevOps: Gitlab ci hands-on experience - Ivan Rimac (Barrage)
PDF
Shift Remote: DevOps: DevOps Heroes - Adding Advanced Automation to your Tool...
PDF
Shift Remote: DevOps: An (Un)expected Journey - Zeljko Margeta (RBA)
PDF
Shift Remote: Game Dev - Localising Mobile Games - Marta Kunic (Nanobit)
PDF
Shift Remote: Game Dev - Challenges Introducing Open Source to the Games Indu...
PDF
Shift Remote: Game Dev - Ghost in the Machine: Authorial Voice in System Desi...
PDF
Shift Remote: Game Dev - Building Better Worlds with Game Culturalization - K...
PPTX
Shift Remote: Game Dev - Open Match: An Open Source Matchmaking Framework - J...
PDF
Shift Remote: Game Dev - Designing Inside the Box - Fernando Reyes Medina (34...
PDF
Shift Remote: Mobile - Efficiently Building Native Frameworks for Multiple Pl...
PDF
Shift Remote: Mobile - Introduction to MotionLayout on Android - Denis Fodor ...
PDF
Shift Remote: Mobile - Devops-ify your life with Github Actions - Nicola Cort...
PPTX
Shift Remote: WEB - GraphQL and React – Quick Start - Dubravko Bogovic (Infobip)
Shift Remote: AI: How Does Face Recognition Work (ars futura)
Shift Remote: AI: Behind the scenes development in an AI company - Matija Ili...
Shift Remote: AI: Smarter AI with analytical graph databases - Victor Lee (Ti...
Shift Remote: DevOps: Devops with Azure Devops and Github - Juarez Junior (Mi...
Shift Remote: DevOps: Autodesks research into digital twins for AEC - Kean W...
Shift Remote: DevOps: When metrics are not enough, and everyone is on-call - ...
Shift Remote: DevOps: Modern incident management with opsgenie - Kristijan L...
Shift Remote: DevOps: Gitlab ci hands-on experience - Ivan Rimac (Barrage)
Shift Remote: DevOps: DevOps Heroes - Adding Advanced Automation to your Tool...
Shift Remote: DevOps: An (Un)expected Journey - Zeljko Margeta (RBA)
Shift Remote: Game Dev - Localising Mobile Games - Marta Kunic (Nanobit)
Shift Remote: Game Dev - Challenges Introducing Open Source to the Games Indu...
Shift Remote: Game Dev - Ghost in the Machine: Authorial Voice in System Desi...
Shift Remote: Game Dev - Building Better Worlds with Game Culturalization - K...
Shift Remote: Game Dev - Open Match: An Open Source Matchmaking Framework - J...
Shift Remote: Game Dev - Designing Inside the Box - Fernando Reyes Medina (34...
Shift Remote: Mobile - Efficiently Building Native Frameworks for Multiple Pl...
Shift Remote: Mobile - Introduction to MotionLayout on Android - Denis Fodor ...
Shift Remote: Mobile - Devops-ify your life with Github Actions - Nicola Cort...
Shift Remote: WEB - GraphQL and React – Quick Start - Dubravko Bogovic (Infobip)
Ad

Recently uploaded (20)

DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Review of recent advances in non-invasive hemoglobin estimation
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPTX
Big Data Technologies - Introduction.pptx
PDF
Electronic commerce courselecture one. Pdf
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Approach and Philosophy of On baking technology
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
The AUB Centre for AI in Media Proposal.docx
Building Integrated photovoltaic BIPV_UPV.pdf
Encapsulation_ Review paper, used for researhc scholars
Spectral efficient network and resource selection model in 5G networks
The Rise and Fall of 3GPP – Time for a Sabbatical?
Review of recent advances in non-invasive hemoglobin estimation
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Big Data Technologies - Introduction.pptx
Electronic commerce courselecture one. Pdf
Chapter 3 Spatial Domain Image Processing.pdf
MYSQL Presentation for SQL database connectivity
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Approach and Philosophy of On baking technology
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Digital-Transformation-Roadmap-for-Companies.pptx
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Per capita expenditure prediction using model stacking based on satellite ima...
NewMind AI Weekly Chronicles - August'25 Week I
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication

More Than You Ever Wanted to Know About Resource Hints - Harry Roberts (CSS Wizardry)