Should you use CDN for your website
Should you use CDN
To determine whether or not to use CDN. We first need to take a look at what is CDN. CDN stands for Content Delivery Network or Content Distribution Network. In simple words CDN is a medium to deliver website’s static content to user from nearest possible data server. Based on user’s Geo-location. This means there are few hopes between server and user. Thus it results in faster content delivery. The CDN providers have multiple data centers located in various geographies. They automatically detects the users location and serves the data from nearest data center for faster response. For more information about CDN, technology and trend information consider this wikipedia article. And if you are on Amazon cloud hosting network and not willing to pay for CDN services, follow this article to setup your own CDN on Amazon S3 with cloudfront.
The below image shows single server content delivery(Left) and CDN delivery (Right).
The left image represent usual website hosting without CDN. Where all the requests are responded by single server. This may increase website load time for the users who have longer Geo distance from website. The right image represents website hosting with CDN. Here all the static components given to CDN data centers. They mirror the content to various data centers. When user request for website it serve the request from nearest data center. CDN services also supports caching for even faster resource delivery.
Advantages of CDN
There are some possibilities that resources website is using may be cached on user browser. Say for instance, jQuery now every other website uses it. Meaning user may have visited some other website with uses jQuery CDN. Now when the user visit your website chances are browser will use the cached version jQuery instead of requesting server for resource.
Ideally browsers allow 4 active request to domain for content. Other request need to be queued till any of the slot becomes free. CDN gives extra edge here by offering multiple multiple domain for the content delivery. Meaning your website can make multiple request for resources to different domain at a time. This reduces the queue time and loads content faster.
Distinct Geo located data centers
When you host your static entities to CDN hosting. They host that content to various Geo located data centers for faster delivery. For instance your website is hosted in Australia and a user comes from USA. Ideally the response needs to pass n number of network hopes to reach to user. But CDN detects the nearest located data center and respond. It reduces the network hopes and faster the response.
Generally good CDN provider offers highest up-time/availability, builtin fail-over and lower data packet loss. Web hosting infrastructure would be good but it would be match the scalability, capacity and fail-over support of CDN.
Disadvantages of CDN
This may be a rare case but if CDN data-center or services are down. You can’t do anything but wait till gets up. Or you can write failover logic that look for local server based resources instead at coast of additional development.
Security would be concern if you use public CDN services. Especially remote hosted Java-Scripts can be altered to collect/store user’s and system data information.
Some countries may ban the IP address of CDN provider. Risk is that your website may not behave or look as it should ideally on user’s machine. Though you can control it via fail-over technique to lookup for local resource, but that would loose the CDN advantage.
Use CDN would not offer content optimization. Meaning CDN hosted libraries are good for general development. It will load entire library no matter if you require specific set of feature from that resource. In this case you need to alter the resource create the file and host it to your own server.
Should you use CDN?
Answer would be yes if you have large website with lot of resources and have high traffic. It will help you improve load-time significantly.
You can obviously use CDN for resources with small website with limited amount of resources but effect would not be that significant. You can consider using popular public CDN for jQuery, Bootstrap and Angular.JS like public resources. That will defiantly help.