--- url: "https://web.dev/articles/preconnect-and-dns-prefetch" titulek: "Establish network connections early to improve perceived page speed | Articles | web.dev" h1: "Establish network connections early to improve perceived page speed Stay organized with collections Save and categorize content based on your preferences." popis: "Learn about rel=preconnect and rel=dns-prefetch resource hints and how to use them." jazyk: "en" kanonicka: "https://web.dev/articles/preconnect-and-dns-prefetch" drobecky: ["Articles", "Establish network connections early to improve perceived page speed"] zdroj: "live" wayback_snapshot: "" stazeno: "2026-09-14 00:57:04" znaku: 8755 slov: 1304 kodovani: "iso-8859-2" sha256: "bdbcf339b4aff5ff39299a98a5129ef4d41282fd9ecc7a7fb94687c465b50118" --- Establish network connections early to improve perceived page speed Stay organized with collections Save and categorize content based on your preferences. Learn about rel=preconnect and rel=dns-prefetch resource hints and how to use them. Jeremy Wagner Milica Mihajlija Before the browser can request a resource from a server, it must establish a connection. Establishing a secure connection involves three steps: Look up the domain name and resolve it to an IP address. Set up a connection to the server. Encrypt the connection for security. In each of these steps the browser sends a piece of data to a server, and the server sends back a response. That journey, from origin to destination and back, is called a [round trip](https://developer.mozilla.org/docs/Glossary/Round_Trip_Time_(RTT)). Depending on network conditions, a single round trip might take a significant amount of time. The connection setup process might involve up to three round tripsâand more in unoptimized cases. Taking care of all that ahead of time makes applications feel much faster. This post explains how to achieve that with two resource hints: `` and ``. Establish early connections with `rel=preconnect` Modern browsers [try their best to anticipate](https://www.igvita.com/posa/high-performance-networking-in-google-chrome/#tcp-pre-connect) what connections a page will need, but they cannot reliably predict them all. The good news is that you can give them a (resource đ) hint. Adding `rel=preconnect` to a `` informs the browser that your page intends to establish a connection to another domain, and that you'd like the process to start as soon as possible. Resources will load more quickly because the setup process has already been completed by the time the browser requests them. Resource hints get their name because they are not mandatory instructions. They provide the information about what you'd like to happen, but it's ultimately up to the browser to decide whether to execute them. Setting up and keeping a connection open is a lot of work, so the browser might choose to ignore resource hints or execute them partially depending on the situation. Informing the browser of your intention is as simple as adding a `` tag to your page: `` You can speed up the load time by 100â500 ms by establishing early connections to important third-party origins. These numbers might seem small, but they make a difference in how [users perceive web page performance](/articles/user-centric-performance-metrics). Use-cases for `rel=preconnect` Knowing *where from*, but not *what* you're fetching Due to versioned dependencies, you sometimes end up in a situation where you know you'll be requesting a resource from a particular CDN, but not the exact path for it. An example of a versioned URL. The other common case is loading images from an [image CDN](/articles/image-cdns), where the exact path for an image depends on media queries or runtime feature checks on the user's browser. An example of an image CDN URL. In these situations, if the resource you'll be fetching is important, you want to save as much time as possible by pre-connecting to the server. The browser won't download the file until your page requests it, but at least it can handle the connection aspects ahead of time, saving the user from waiting for several round trips. Streaming media Another example where you may want to save some time in the connection phase, but not necessarily start retrieving content right away, is when streaming media from a different origin. Depending on how your page handles the streamed content, you may want to wait until your scripts have loaded and are ready to process the stream. Pre-connecting helps you cut the waiting time to a single round trip once you're ready to start fetching. How to implement `rel=preconnect` One way of initiating a `preconnect` is adding a `` tag to the `
` of the document. ` ` Preconnecting is only effective for domains other than the origin domain, so you shouldn't use it for your site. You can also initiate a preconnect via the [`Link` HTTP header](https://developer.mozilla.org/docs/Web/HTTP/Headers/Link): `Link: