Content Delivery Network is a structure of network meant to dispense data (static) to the user from the server nearest to the user’s location. CDN Integration adds that much-needed benefit of speeding up the website. As already mentioned in my previous article about ways to speed up WordPress e-commerce website , CDN is a bit costlier than you think. But little people know that you can even set up SELF CDN. Isn’t this amazing? Self CDN is creating your own CDN network to improvise your site’s performance. Self-hosted CDN just like any other CDN service helps in optimizing your website speed.
Why do we need CDN?
So let’s see how the browser responds to your request when you visit any website. When you visit any URL, the browser first connects to the DNS server the get the required data to render the correct page which you have asked for. With the help of DNS browser connects to your server to fetch the data being requested.
But the drawback here is browser can carry only a specific number of files at a time. In this case, if a server has let’s say 200 files needed to render the page, the browser will carry this files in patches. In turn which will apparently increase the loading time of your website. As we are aware that a WordPress itself has a large number of files, which makes it a bit slow. This is where Self CDN can do the job for you.
How does Self Hosted CDN work?
Self Hosted CDN isn’t a real network but, It helps by parallelizing downloads across different domains. Self CDN draws static content from different subdomains, unlike the usual one where the data is dispensed from a single server. It is not necessary that you buy a new server to setup a self-hosted CDN you can use the same server by transferring some of the static content files to a subdomain or a new domain and store on the same server. This will just enable the browser to carry twice the number of records at a single request. As in this case browser sets two different connections to the server ultimately allowing it to take twice the number of files.
How to setup Self Hosted CDN?
Setting up Self Hosted CDN to your WordPress site is quite simple. All we need is W3 Total Cache Plugin. For the further listed steps, we’ll be using a local subdomain as our CDN address to store static content.
1. Turn on the CDN features in the general Setting and select the option of Generic Mirror in the field of CDN Type.
- -Host attachments
- -Host Theme files
- -Host minified CSS and JS files
- -Host Custom Files.
Don’t forget to save your changes.
3. As we are using the local subdomain for the CDN service, we need to have one ready. This can be created by logging into your cPanel account and go to the subdomain section. Create a subdomain of whichever name you want your CDN address to be. Here we will be using cdn1 as our subdomain.
4. Assign your subdomain to the ‘public_html’ folder so as to make it function like a Generic Mirror.
5. Go to cPanel’s advance DNS Zone Editor. Edit the cName of the newly created subdomains. While editing them, you need to change the Type to CNAME and adding the subdomain in the Name field, which will complete our Generic Mirror Settings
6. Now in the W3 Cache Configuration change, the CDN Hostname to the Self-Hosted CDN address – the subdomains we just created.
7. Next, we need to modify attachment URL’s present in the W3 Cache CDN settings. Here we just need to add subdomain and modify the URL.
Then all you need to do is HIT the START button.
Its, done. You have successfully created your Self CDN in quite a few steps, and you are ready to go.