Modern websites rely on many external sources and files, such as images, embeddable content, and web development frameworks. Many of these may be used by users across many countries, making storing them on one server slow for users not in the same country as the backend server. Content delivery networks (CDNs) fix this and provide extra benefits, bringing websites significant performance improvements. But what is a CDN, and how do CDNs work?
What is a CDN?
CDNs are clusters of servers located across the world hosting files needed by a backend server. Files uploaded to these networks are mirrored to every server in the network. When a website makes a request to one of these networks, the closest server is picked to minimize the time it takes for the files to be transferred to the client. Additionally, many networks provide extra features, such as load balancing and distributed denial of service (DDoS) prevention.
Networks of this type are utilized by almost every popular website on the internet. They are typically used to host web frameworks, such as jQuery, React, and Angular. Common images found on the internet (e.g. Google’s logo) are also typically hosted by these networks due to their popularity. Many other types of static content, including videos and audio, are also found on these networks to reduce strain on backend servers. Implementing a CDN with your website is going to increase the website speed, and if you need help in implementing a CDN with your site, check out Team WP Sekure website speed optimization service.
How do CDNs work?
Imagine that you own a popular website that contains dozens of images per page. Delivering these images to users from your server is possible but can lead to significant slowdowns if users from other countries are accessing your website. Content delivery networks can distribute these images to many servers across the world and automatically select the server closest to the client. This way, users from any country can access your website with minimal latency.
Additionally, these networks are sometimes used as load balancers. Load balancers take in all internet traffic to a server and distribute it among several backend servers, “balancing” the load to increase performance. Others can also be used to prevent DDoS attacks, blocking attackers and minimizing the damage done while leaving the backend server intact.
Exploiting Browser Caches
The true beauty of how CDNs work, however, is by utilizing browser caches. Most modern browsers store commonly used content in a cache, eliminating the need to download the content every time it is needed. For extremely popular files, such as web frameworks, this can drastically improve load times. The problem is that these files are stored based on their URL, eliminating potential speed-ups for content used across many websites.
Content delivery networks solve this issue by redirecting all requests of this file to a single URL. Most networks that host files of this variety (such as the extremely common jQuery library) have been linked to by thousands of websites, so any new websites that link to them can access these caches, even if users have never accessed that specific site before. This way, any website can tap into the performance increases associated with accessing common files through networks dedicated to sharing them.