There is a belief, quite rightly, that utilising a Content Delivery Network (CDN) for all site resources (images, style sheets, client side scripting files, movies, and so on) can increase the speed of a website dramatically. Whilst using a CDN can have significant improvements in page load times, there is however a slight misconception that this holds just as true when the vast majority of the website’s audience are located in the same country as the server hosting the website. Whilst there are definite speed (page load time) and several other benefits gained from using a CDN, the gain is minimal in such a scenario. When site resources come from a domain other than the website’s domain, there are benefits due to the fact that not all of the cookies and session data from the website visit have to be carried with each request to the resource server. Similarly, CDNs are cached; which means the files do not have to be continuously downloaded as they otherwise would be. However, the benefits described can easily be achieved without the use of the CDN.
The way that CDNs work is by creating a network of datacentres around the globe. When a user requests a file by visiting the website, the CDN decides which datacentre is closest to the user, before the file is served from the point of the CDN. The file may already have been requested from this datacentre within the cache period, which means the file will simply be served to the user straight from the server cache. If the file hasn’t already been requested from this datacentre within that timeframe, and presuming the datacentre is not the central one which the file is served from, a request will be made to the central datacentre. The file will then be served to the user and cached in order to speed things up for the next request.
The real impact that a CDN has is the way it serves data from the closest datacentre to the user. This significantly reduces the amount of hops required between the file being served and the user it is served to. The hops are the points across the network. For example, there may be 10 hops between the datacentre in the UK and a UK visitor, whereas from the same datacentre going to a user in China there could be 30 hops. Each of these hops takes a small increment of network time to be served; meaning that the file would be served much more slowly to the user in China.
When viewing websites from other countries you may have noticed that they are often very slow - likely due to this very reason. When a CDN is involved, the user in China would be served the file from their local datacentre. This means there would be a closer amount of hops between the file and their computer, as there would be for a UK user. As a result load times of the pages would then similarly be much closer.
As you can see, CDNs can be very powerful facilities, and there are other benefits not described above, such as greater redundancy. If your objective is purely to improve the page load times of your website and your audience is almost entirely from the one country, the most important factor should be to ensure the website is hosted in the same country in which your audience is based. After that there are measures you can take to optimise the resources, such as utilising an alternative domain and setting up effective caching - but a CDN is not the answer.