Loading...
function App() {
preconnect('https://cdn.example.com');
preconnect('https://maps.example.com');
preconnect('https://chat.example.com');
return <Page />;
}function App() {
preconnect('https://cdn.example.com');
prefetchDNS('https://maps.example.com');
prefetchDNS('https://chat.example.com');
return <Page />;
}Only the origin needed right away gets a full connection; the others just resolve DNS, which costs far less.
prefetchDNS is imported from 'react-dom' and receives only a URL of another origin.preconnect instead, which also opens the connection.Yes. During server rendering React adds a dns-prefetch link to the HTML head, and on the client it inserts the tag.
Yes. Calling it in a handler, such as on hover before a navigation, starts the lookup before the request is made.