Support

Find answers, guides, and tutorials to supercharge your content delivery.

How to Parallelize Downloads Across Hostnames

Updated on October 4, 2018
How to Parallelize Downloads Across Hostnames

The Parallelize Downloads Across Hostnames warning was an optimization recommendation previously suggested by many popular speed test tools such as Pingdom, GTmetrix, PageSpeed Insights, and more.

This warning is becoming less and less important as more website owners move to HTTP/2. HTTP/2 allows multiple resources to be loaded in parallel using only one connection. However, for those still using HTTP/1.1 and loading multiple resources, it can be beneficial to implement what's called domain sharding.

This guide will walk through the process of how you can fix the parallelize downloads across hostnames issue using two different methods.

What Does Parallelize Downloads Across Hostnames Mean?

Parallelizing downloads across hostnames means setting up multiple subdomains within a website so that each subdomain can handle the loading of different assets. For example, let's say you have a website which contains 18 resources in total, besides the HTML doc: 6 CSS files, 6 JS files, and 6 images. In this case, you could then setup a specific subdomain to load the assets of each file type:

  • css.yourwebiste.com would load the 6 CSS files
  • js.yourwebsite.com would load the 6 JS files
  • img.yourwebsite.com would load the 6 images

For browsers accessing websites over HTTP/1.1 this would be an optimal setup as browsers handle about 6 concurrent connections per hostname on average. Therefore setting up multiple hostnames allows the browsers to handle more concurrent connections at once.

Resolving the Issue Using HTTP/2

If you're still using a web host or CDN that is running HTTP/1.1, it is highly recommended to migrate to one that offers HTTP/2 support. HTTP/2 is the new web standard and offers an array of benefits over HTTP/1.1.

For starters, the parallelize downloads across hostnames recommendation is no longer required for those using HTTP/2. Most speed test tools have updated their recommendations section to not even include the parallelize downloads across hostnames recommendation anymore. However, it should be noted that if you do come across a speed test tool recommending this suggestion it can be safely ignored as long as you are sure your server is using HTTP/2. To check whether your server or CDN supports HTTP/2 use our HTTP/2 check tool.

Resolving the Issue Using Domain Sharding (Not Recommend)

As mentioned above, if you are still using HTTP/1.1 and want to parallelize downloads across hostnames, you'll need to implement domain sharding. This is not the recommended method and it's much easier and better overall to upgrade your server to HTTP/2.

However, if you do still want to proceed with domain sharding, you'll first need to create multiple CNAME records (no more than 4) in your DNS settings that point to your content directory. If using WordPress this would be /wp-content. Therefore, for simplicity's sake let's say your subdomains are:

static1.yourwebsite.com
static2.yourwebsite.com
static3.yourwebsite.com

One of your CNAME records would, therefore, resemble the following in cPanel:

Once all of your subdomains are created, you would then need to add the following code to your functions.php file, if using WordPress. Ensure you replace media1.mydomain.com and media2.mydomain.com with your actual subdomains.

function parallelize_hostnames($url, $id) {
    $hostname = par_get_hostname($url); // call supplemental function
    $url = str_replace(parse_url(get_bloginfo('url'), PHP_URL_HOST), $hostname, $url);
    return $url;
}

function par_get_hostname($name) {
    $subdomains = array('media1.mydomain.com','media2.mydomain.com'); // add your subdomains here, as many as you want.
    $host = abs(crc32(basename($name)) % count($subdomains));
    $hostname = $subdomains[$host];
    return $hostname;
}

add_filter('wp_get_attachment_url', 'parallelize_hostnames', 10, 2);

Alternatively, if you're using a CDN to deliver your static content, you'll simply need to create multiple CNAMEs (e.g. cdn1.yourwebsite.com, cdn2.yourwebsite.com, etc) and point them to your Zone URL. You can then use these custom CDN URLs in conjunction with a CDN integration method that supports domain sharding.

Summary

Although the parallelize downloads across hostnames recommendation isn't overly relevant anymore, certain website speed test tools may still recommend it if your server is using HTTP/1.1. If your website falls into this category, strongly consider moving to a web host which offers HTTP/2 support so that you can take advantage of faster load times and a more up to date HTTP protocol.

Supercharge your content delivery 🚀

Try KeyCDN with a free 14 day trial, no credit card required.

Get started
KeyCDN uses cookies to make its website easier to use. Learn more