Preconnect

On this page 7

Preconnect is a resource hint, written as <link rel="preconnect" href="https://origin.example">, that tells the browser to set up a connection to another origin in advance, completing the DNS lookup, the TCP handshake and the TLS negotiation before the page actually requests anything from that origin. When the request arrives, it can be sent immediately over a warm connection.

Web performance practice treats preconnect as a low-cost way to remove connection latency from the critical path, especially for third-party fonts, image CDNs, API hosts and analytics endpoints. Used selectively, it can improve LCP and FCP by tens to hundreds of milliseconds; used indiscriminately, it wastes sockets and processor time on connections that are never used.

How preconnect removes connection setup time

Preconnect removes connection setup time by performing the network handshakes in parallel with other work, instead of waiting until the browser discovers a resource on that origin. Without the hint, the browser learns about a cross-origin font, for example, only after it has downloaded and parsed the stylesheet that references it.

Each new HTTPS connection requires several round trips. On a mobile network with a round-trip time of 100 to 300 ms, the combined cost easily reaches 300 to 900 ms before a single byte of the resource is transferred. Preconnect moves that cost earlier, so it overlaps with HTML parsing and other downloads.

The table breaks down the steps that preconnect performs and their typical cost.

StepRound tripsWhat happens
DNS resolutionUsually 1, often cachedHostname is translated to an IP address
TCP handshake1SYN, SYN-ACK and ACK establish the socket
TLS 1.3 handshake1Keys are agreed and the certificate is verified
TLS 1.2 handshake2Older protocol needs an extra exchange
QUIC with HTTP/31, combinedTransport and encryption set up together
Connection steps completed by preconnect

The browser treats the hint as advisory. It may skip it under memory pressure, on data saver modes or when too many connections are already open, so preconnect is an optimization, never a guarantee.

Preconnect compared with other resource hints

Preconnect differs from other resource hints in how much work it starts: it prepares the connection but downloads nothing. That distinguishes it from Preload, which fetches a specific file, and from Prefetch, which fetches a resource likely to be needed on a later navigation.

The comparison below places preconnect among the related hints.

HintWork performedCost if unusedBest for
dns-prefetchDNS lookup onlyVery lowMany possible origins, older browsers
preconnectDNS, TCP and TLSLow to moderateA few critical third-party origins
preloadFull download of one resourceBandwidth for the fileLate-discovered critical assets
prefetchLow-priority download for laterBandwidth, idle timeNext-page resources
modulepreloadDownload and parse of a JS moduleBandwidth and parsingModule dependency graphs
Resource hints and what each one does

A frequent pattern pairs preconnect with dns-prefetch on the same origin. Browsers that support preconnect use it, and the others fall back to the cheaper DNS step. Preconnect is also superfluous for the page’s own origin, because the connection already exists after the HTML document is fetched.

Implementing preconnect correctly

Preconnect is implemented either with a link element in the head or with an HTTP Link header, and the header form lets the browser act before it parses any HTML. A typical header looks like Link: <https://cdn.example>; rel=preconnect. Servers can also send it in a 103 Early Hints response while the main page is still being generated.

The crossorigin attribute is the detail that most often breaks the hint. Browsers keep separate connection pools for anonymous and credentialed requests, so a preconnect without crossorigin does not help a font, which is always fetched in CORS anonymous mode. The result is a second, unused handshake.

The table helps decide when the attribute is needed.

Resource on the originRequest modePreconnect setting
Web fontsCORS anonymousAdd crossorigin
Fetch or XHR without credentialsCORS anonymousAdd crossorigin
Classic scripts and stylesheetsNo CORSOmit crossorigin
Images without the attributeNo CORSOmit crossorigin
Mixed resource typesBoth modesUse two hints, one with and one without
When to add the crossorigin attribute

Placement matters as well. The hint should appear as early as possible in the head, before render-blocking stylesheets and scripts, so that the browser can start the handshake while it waits for them.

Choosing which origins to preconnect

The right origins to preconnect are those that serve critical resources within the first few seconds of loading and that the browser discovers late. Good candidates are font hosts, the CDN that delivers the LCP image and an API origin whose response renders above-the-fold content.

Practitioners commonly limit preconnect to two to four origins. Each open connection consumes memory, competes for bandwidth during TLS and costs processor time for certificate verification, which on low-end phones can delay more important work. Browsers also close idle connections after a timeout, often around ten seconds, so a hint for a resource needed much later is wasted.

  • Preconnect to origins needed for above-the-fold rendering.
  • Use dns-prefetch instead for origins needed later or only on some pages.
  • Remove hints for origins the page no longer uses after a redesign.
  • Prefer self-hosting critical assets when possible, which removes the extra connection entirely.

Measuring the effect of preconnect

The effect of preconnect is measured by checking whether connection phases disappear from the critical request in a waterfall chart. In a successful case, the font or image request shows no DNS, connect or SSL segments, because those phases finished earlier.

Lab tools in Synthetic monitoring reveal this clearly, and audit tools flag both missing and unused hints. Field data from Real user monitoring then confirms whether metrics such as LCP and TTFB of third-party requests improved for actual visitors.

The table lists the warning signs that a hint is misconfigured.

SymptomLikely causeCorrection
Two connections to the same font hostMissing crossorigin attributeAdd crossorigin to the hint
Console warning about an unused preconnectOrigin not requested within secondsRemove the hint or use dns-prefetch
No change in the waterfallHint placed after blocking resourcesMove it to the top of the head
Slower start on low-end devicesToo many preconnected originsReduce to the most critical origins
Symptoms of an ineffective preconnect

A non-technical view

Before a browser can fetch anything from another website, it must do some setup. It has to look up the address, knock on the door and agree on a secret handshake. Each of these steps takes a moment, and on a slow phone network the moments add up.

Preconnect is like calling ahead to a restaurant so the table is ready when you arrive. The browser does the introductions early, while it is busy with other things. Then, when the page finally asks for a font or a picture, the delivery can start right away instead of waiting.

A concrete example

A recipe website loads its hero photo from an image CDN and its typefaces from a separate font host. A waterfall test on a simulated 4G connection with a 150 ms round-trip time shows that both requests spend about 450 ms on DNS, TCP and TLS before downloading anything, and the hero photo is the page’s LCP element.

The developer adds <link rel="preconnect" href="https://img.cdn.example"> and, for the font host, a second hint with the crossorigin attribute, placing both at the top of the head. A rerun shows the connection phases completed during HTML parsing, and LCP drops from 3.1 s to about 2.6 s in lab tests.

Field data collected over the next month confirms a smaller but consistent gain for mobile visitors, and the team documents a rule to review preconnect hints at every redesign so unused ones are removed.