Course contentsShow
← Web Development
Lesson 2052 of 2,98237. Image and Asset OptimizationFree lesson

Resource Hints for Third-Party Domains

Use dns-prefetch, preconnect, and preload to optimize connections to external script domains.

Resource Hints for Third-Party Domains

You'll learn how to use resource hints to speed up connections to external domains hosting third-party scripts, fonts, and assets.

The Problem with Third-Party Domains

When your page loads a script, font, or image from a third-party domain (like Google Fonts, analytics providers, or CDNs), the browser must perform several time-consuming steps: DNS lookup, TCP connection, and TLS negotiation. Each of these can add 100-500ms of delay before the actual resource downloads.

Using Resource Hints Strategically

You've already learned about dns-prefetch, preconnect, and preload individually. Now you'll apply them specifically to third-party domains to eliminate these connection delays.

dns-prefetch for Early DNS Resolution

<link rel="dns-prefetch" href="https://www.google-analytics.com">
<link rel="dns-prefetch" href="https://cdn.example.com">

Use this when you know you'll eventually need resources from a domain but not immediately (low-priority third parties).

preconnect for Full Connection Setup

<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>

This goes further—resolving DNS and establishing the full connection. Use for critical third-party resources you'll need soon (like web fonts or important scripts).

preload for Specific Third-Party Assets

<link rel="preload" href="https://cdn.example.com/critical.js" as="script">
<link rel="preload" href="https://fonts.gstatic.com/s/roboto/v30/font.woff2" as="font" crossorigin>

When you know the exact URL of a critical third-party resource, preload it directly to start downloading immediately.

The Strategy

Think of it as a spectrum: dns-prefetch is cheapest (just DNS), preconnect does more work (DNS + connection), and preload commits to downloading a specific file. Use the lightest hint that meets your needs—don't preconnect to 20 domains!

Key Takeaway: Apply resource hints to third-party domains to eliminate connection overhead—use dns-prefetch for low-priority domains, preconnect for important ones, and preload for specific critical assets you know you'll need.