Page Speed: Parallelize downloads across hostnames More Recommendations

Rule Summary

Content
High
Hard

Overview

Serving resources from four or five different hostnames increases parallelization of downloads.

How does your site score on this rule?

Details

Web browsers put a limit on the number of concurrent connections they will make to a host. When there are many resources that need to be downloaded, a backlog of resources waiting to be downloaded will form. The browser will make up as many simultaneous connections to the server as the browser allows in order to download these resources, but then will queue the rest and wait for the requests to finish.

The time spent waiting for a connection to finish is referred to as blocking and reducing this blocking time can result in a faster loading page. The waterfall diagram below shows a page which loads 45 resources from the same host. Notice how long the resources are blocked (the brown segments), before they are downloaded (the purple segments) as they wait for a free connection.

Waterfall without domain sharding
Waterfall diagram of a page without domain sharding

One way to improve the situation is to create multiple sub-domains (eg. static1.gtmetrix.com, static2.gtmetrix.com) so that the number of resources downloaded in parallel is increased. This is referred to as "domain sharding." Because browsers limit connections on a per host basis, creating a sub-domain adds a new pool of connections that the browser can make, allowing more resources to be downloaded at the same time. Taking the same page as above and splitting the resource requests between two domains, you can see that a lot less time is spent blocking and the page loads about 33% faster:

Waterfall sharded across two domains
Waterfall diagram with resources sharded across two domains (same time scale as above)

Domain sharding can have a negative effect on performance - it adds DNS request time as well as connection time to each new concurrent connection to the shard (as seen by the green segments in the waterfall); but if utilized correctly, can drastically improve resource load time. Before implementing it, you should read more about the common problems with domain sharding.

Our Recommendations

Your first step towards reducing blocking time should be the reducing the number of resources needed to be downloaded (eg. combine external CSS/JS and use sprites). However, in situations where these optimizations don't help as much (eg. a shopping or image gallery where you can’t sprite the images),domain sharding can often help alleviate the problem.

If your site spends a significant time blocking, or a majority of your users use a older browser like IE6/7, then implementing domain sharding should result in significant performance gains. However, depending on how URLs are generated and where resources are being loaded from, implementing domain sharding can be a difficult and time consuming task. If you’ve already reduced the number resources your site loads but still aren’t happy with performance, domain sharding is worth a try.

More GTmetrix Resources

For more details on domain sharding, take a look at our extended resources:

recommends:

Balance parallelizable resources across hostnames

Requests for most static resources, including images, CSS, and other binary objects, can be parallelized. Balance requests to all these objects as much as possible across the hostnames. If that's not possible, as a rule of thumb, try to ensure that no one host serves more than 50% more than the average across all hosts. So, for example, if you have 40 resources, and 4 hosts, each host should serve ideally 10 resources; in the worst case, no host should serve more than 15. If you have 100 resources and 4 hosts, each host should serve 25 resources; no one host should serve more than 38.

On the other hand, many browsers do not download JavaScript files in parallel*, so there is no benefit from serving them from multiple hostnames. So when balancing resources across hostnames, remove any JS files from your allocation equation.

*For a list of browsers that do and do not support parallel downloading of JavaScript files, see Browserscope.

Prevent external JS from blocking parallel downloads

When downloading external JavaScript, many browsers block downloads of all other types of files on all hostnames, regardless of the number of hostnames involved. To prevent JS downloads from blocking other downloads (and to speed up the JS downloads themselves):

Always serve a resource from the same hostname.

To improve the browser cache hit rate, the client should always fetch a resource from the same hostname. Make sure all page references to the same resource use the same URL.

Read More

Contribute to this recommendation

Have an opinion, link, or other contribution to share regarding this recommendation? Share it with us and help make the web a faster place!