How to Parallelize Downloads Across Hostnames

Parallelize downloads on sites using HTTP/1.1 to improve page speeds

Cutting White Colored Paper into Strip Roll Against Black Paper Directly Above View

Mirage C / Getty Images

Some bandwidth speed testing tools may recommend sites parallelize downloads across hostnames to serve web content to web browsers effectively. This recommendation usually occurs on sites that use the HTTP/1.1 protocol and happens when web browsers limit the number of simultaneous connections made to a domain. Websites that have many HTTP requests for static content such as images, CSS files, and JavaScript encounter a Parallelize Downloads Across Hostnames warning. To get around this limitation, set up domain sharding or use a content delivery network (CDN).

Why Parallelize Downloads Across Hostnames?

Web browsers can only open a limited number of concurrent connections per hostname for websites that use the HTTP/1.1 protocol. This limit may be as high as six connections. When more resources need to be downloaded, the additional resources must wait in a backlog queue until there’s an available connection. The resources in the queue are blocked and reducing this blocking time results in faster page load times.

For example, if a web page has 12 images and the number of connections allowed by the web browser is six, then six images must wait in the backlog. The images in the backlog stay there until the first six images have finished downloading.

If an image such as an icon or logo is used multiple times, use a CSS Sprite for these repeated images to reduce resource requests.

What is the Parallelize Downloads Across Hostnames Warning?

The parallelize downloads across hostnames warning is a rule used in some website performance checkers. The warning indicates that that web browser couldn’t open the number of connections needed to download all the website resources simultaneously.

For websites that use the HTTP/1.1 protocol, the way to get around this need for more open connections is to minimize HTTP requests, set up a CDN, or implement domain sharding.

For websites that use the HTTP/2 protocol, multiple resources can load in parallel over a single connection; this is called multiplexing. Multiplexing makes domain sharding unnecessary with HTTP/2. About 77% of web browsers support HTTP/2 and shouldn’t encounter any issue with parallelizing downloads.

If your web hosting provider supports HTTP/2, it’s safe to ignore the parallelize downloads across hostnames warning. With HTTP/2, multiple resources can download in parallel on one connection.

What is Domain Sharding?

Domain sharding is a performance optimization method for HTTP/1.1 connections and is used on websites with a large volume of HTTP requests. In domain sharding, web content assets are distributed among several subdomains. When assets are distributed this way, the number of simultaneous requests that can be processed increases.

In domain sharding, content is uploaded on cookie-free subdomains. Users don’t interact with static content such as images, JavaScript, and CSS files, so this content doesn’t need to be attached to cookies. When subdomains don’t serve cookies, the size of requests made for a page and request latency decrease and web pages load faster. Examples of content that benefits from domain sharding include pages with content that is rarely cached such as a page of thumbnails or an image archive.

In Drupal, modules add CSS and JavaScript files that can slow performance. Go to Site Config > Performance and optimize CSS and JavaScript.

To take advantage of the benefits of domain sharding on HTTP/1.1 connections, follow these tips:

  • Serve resources from the same subdomains to efficiently cache files.
  • Distribute resources evenly among subdomains.
  • Purchase SSL certificates for the subdomains.

On HTTP/2 connections, domain sharding reduces performance because there are additional DNS lookups. These DNS lookups increase resolution time and don’t cache files. Domain sharding also adds time to each new connection. These are other disadvantages of domain sharding on HTTP/2 connections:

  • Distributing resources that load from CSS are difficult to distribute between sharded hosts.
  • Higher load on the server from the increased number of concurrent connections.
  • Moving static content to a subdomain can break code.
  • The web browser may not allow access to a different hostname.
  • Routers may not be able to classify a large number of sharded requests or may see the requests as a denial of service attack.

How to Parallelize Downloads Across Hostnames

When you receive the parallelize downloads across hostnames warning, you’ll need to increase download parallelization by distributing requests among multiple hostnames. To distribute requests, create subdomains for the different types of web assets used on the site, then specify the root domain as the only domain that uses cookies. Subdomains do not use cookies.

These subdomains add new sources of connections that the browser can make, and make it possible for more resources to download at one time. When resources are split between subdomains, the web browser spends less time blocking web content and web pages load faster.

For websites that use HTTP/2 and HTTP/1.1, the easiest way to parallelize downloads across hostnames is to use multiple subdomains through a CDN. For websites using HTTP/1.1 and WordPress, set up subdomains and edit the WordPress functions.php file.

Setup Subdomains

To distribute resources across subdomain, create at least one and up to four subdomains; one or two subdomains is recommended. The most common way to create subdomains is to use cPanel, which is offered by most web hosting services.

Examples of subdomains are:

  • media1.mydomain.com
  • media2.mydomain.com
  • media3.mydomain.com
  • media4.mydomain.com

Also, subdomains and hostnames must have the same structure and path. For example, if the image path on the host is www.mydomain.com/wp-content/uploads/, the image path on the subdomains must match, for example, media1.mydomain.com/wp-content/uploads/.

Set Up a CDN to Parallelize Downloads

After the CDN is set up and the subdomains created, point each subdomain to the folder that contains the static content. This way, the content is loaded over the subdomain instead of the main domain.

To point a subdomain, use a DNS Zone Editor in cPanel to create a new CNAME record for each subdomain. In the Name field of the record, enter the subdomain, for example, media.mydomain.com. In the CNAME field, enter the main domain, for example, www.mydomain.com.

After the CNAME records are created and propagated by your web host, add the CNAME records to the CDN zone settings.

Edit the Website Config File in WordPress to Parallelize Downloads

After you set up the subdomains, add this code to the functions.php file of the WordPress theme used for your website. 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);

If you use Jetpack with WordPress, enable the Site Accelerator service to put your images on a WordPress-managed CDN.