What is Preconnect?
Preconnect is a resource hint that tells the browser to initiate an early HTTP connection to a specified domain. This includes tasks like DNS lookup, connecting a TCP, and negotiating a TLS connection.
How to Use Preconnect in HTML
To enable preconnect in HTML, add it as an attribute to a link tag. This can also be invoked via JavaScript or through the Link HTTP header. Enabling preconnect can help speed up the loading of resources from third-party domains.
Is Preconnect the Same as DNS-prefetch?
Preconnect and DNS-prefetch are different. While DNS-prefetch only warms up the local cache, preconnect establishes and maintains a connection with the specified origin. The latter is generally more resource-intensive.
Using Preconnect in CSS
In CSS, the 'rel=preconnect' attribute in a link tag tells the browser that your page aims to connect to another domain. This pre-setup ensures faster resource loading.
Difference Between Preload and Preconnect
Preload loads content necessary for the initial rendering of the current page, while preconnect establishes a server connection but doesn't load any specific resource. Both aim to improve page load times but work differently.
Preconnect to Third-Party Domains
Initiating a preconnect to third-party domains can optimize the loading of resources like images, CSS, or JavaScript files from external servers.
How to Check Your Preconnect
You can check if preconnect is working using Chrome DevTools. Look for the timing tab of the URI where preconnect is defined to see if steps like DNS, Connect, and SSL take negligible time.
Difference Between Preload and Prerender
Both preload and prerender aim to improve loading times. Preload focuses on critical resources for the current page, while prerender prepares an entire future page that the user might navigate to.