What is Prefetch, Preconnect & Prerender?

Fast loading (rendering) of a website is essential in today's world. Most websites go through a basic checklist to make their websites faster. Tools such as Google's PageSpeed Insights, GTmetrix, or WebPageTest check your website and suggest what can be improved to make it load faster.

When it comes to page speed, most developers mainly reduce (minify) files, compress them with gzip, and compress images.

At a more advanced level, there are steps such as caching, using a CDN to distribute resources (recommended if you have visitors from abroad), code splitting, removing JavaScript-blocking code, and so on.

But there are also other techniques that most people don't talk about when discussing how to make your website faster. These performance-enhancing techniques are commonly known as Resource Hints (prefetching techniques). It's a simple way to tell the browser: “Hey browser, I'm sure I'll need resources A, B, and C at some point. So preload them now to make your website faster.” So preload them now so we can serve them quickly later when they're requested.

This takes place during the browser's idle time, when the browser has already loaded the page and therefore isn't doing anything. This means that while a visitor is reading your page or blog post, the browser loads another page in the background and renders it. This way, the page is displayed more quickly as soon as the corresponding link is clicked. In other words: prefetch and prerender.

If you use Google Analytics, you can find out how visitors navigate your website so you can make the most of these techniques.

The following Resource Hints can be used: dns-prefetch, prefetch, preconnect, and prerender.

DNS-Prefetch

A dns-prefetch tells the browser that we need a few resources from a specific URL, so the browser can start handling DNS as soon as possible.

<link rel=”dns-prefetch” href=”//een-website.nl”>

Suppose we're redirected to a-website.co.uk somewhere on the website. We can add the line above to the website's header. After the browser parses the document, it will start handling DNS for a-website.co.uk. This will make subsequent requests to a-website.co.uk a little faster.

Using DNS prefetch can save a lot of time with redirects and on mobile devices or in places where internet speeds are slower.

Prefetching a link

Prefetching is used when we're sure that a visitor will use a particular resource at some point. Don't confuse dns-prefetch with prefetch, as they're used for different purposes. A common use case is prefetching images that may be requested at a certain point. Once the page has loaded, the browser starts looking for the image at, for example: example.es/images/logo.jpg

A prefetch looks like this:

<link rel=”prefetch” href=”http://voorbeeld.nl/afbeeldingen/logo.jpg">

When this line is encountered, the browser requests the image from the specified URL, downloads it, and stores it in the browser cache.

Be careful not to prefetch too many resources or resources that are too large, as your browser may then show you the following error message:

Failed to load resource: net::ERR_CACHE_WRITE_FAILURE

This means the resource we're trying to preload is too large to be written to the browser cache. Use prefetch only if you're absolutely sure the resource will be used at some point.

Preconnect

For a browser, tasks such as handling DNS (translating IP addresses into domain names), the TCP handshake (Transmission Control Protocol), and handling TLS (Transport Layer Security) are relatively resource-intensive.

Preconnect is similar to DNS prefetch, but it can also perform the TCP handshake and TLS handshakes. This saves users time by eliminating these steps.

By adding the following code to the main body of your website, you can connect to a web page in advance.

Pre-render

Prerendering is the ultimate prefetching technique and should be used with care. Prerendering tells the browser to preload all the resources for a given page using the code below:

<link rel=”prerender” href=”https://voorbeeld.nl/bepaalde-pagina">

In fact, at https://voorbeeld.nl/bepaalde-pagina, the browser invisibly loads and stores the page. When the visitor navigates to this page, the browser can easily load the pre-rendered page, providing a better user experience.

In this case, it's important not to use it unnecessarily, as it's more likely to cause problems (unnecessary resource usage) than to make the page faster.

How do I apply it?

Using our Managed WordPress package? Then you don't have to do it yourself—we take care of all the hassle for you.

Is the website still slow?

It's not just these techniques that make a website incredibly fast; of course, it's important to have a good foundation (web hosting) for your website. Not hosted with WP Provider yet? Get in touch to discuss the options.

Request web hosting

Request your hosting account below!

Request a benchmark now

Do you feel like your website could be faster? Let us run a benchmark. We guarantee that your website will run faster on our hosting!