Loading...
function App() {
preconnect('https://fonts.gstatic.com');
return <Page />;
}function App() {
preconnect('https://fonts.gstatic.com', { crossOrigin: 'anonymous' });
return <Page />;
}Font files load with CORS, so the early connection must use the same crossOrigin mode or the browser opens a new one.
preconnect is imported from 'react-dom' and called in render or an event handler.crossOrigin matching the later request.preconnect resolves DNS and opens the TCP and TLS connection. prefetchDNS only resolves DNS, which is cheaper for less certain origins.
No. The browser is already connected to the page's origin, so preconnect only helps for other origins.