Customer Happiness Manager at PressMate April 25, 2018

What is CDN and how to use it for your WordPress website

With increasing online business and internet market comes great traffic and with increasing volume and traffic, the resources need to scale accordingly. However, scaling the resources cannot guarantee a boost in the performance. A central server may not be able to process the information for multiple users across the globe at the same speed. To overcome this issue, using a CDN is suggested.

CDN stands for Content Delivery Network. It is a system of distributed servers that deliver webpages and it’s related content based on geographical location of the user. CDN comprises of a globally distributed network of web servers in order to provide fast delivery of content. Webpages and all it’s related content (viz. Images, scripts, stylesheets, etc) are replicated by CDN making the same content available at multiple locations at the same time.

In other words, CDN is useful in improving user experience by providing resources in an efficient manner. Many E-commerce vendors and media companies pay to the CDN operators to deliver their content to their viewers.

CDN is very effective to speed up the delivery of content on a website, that have high traffic and global reach. The more closer CDN server is to the user, faster will be the content delivery.

CDN functionality works in two ways

  1. Keep important content distributed to multiple, globally distributed data centers, so your content will be closer to end users
  2. Use server optimizations based on content type to increase the efficiently

The best part about CDN is that your end user will never understand that you are using it as the URL never changes thus making it the best way to optimize content delivery

Now that we know how CDN can help us improve the overall performance, let’s see how can we setup one for our WordPress site

Step 1: Get a CDN account with a CDN provider

First things first, you will need a CDN account with a CDN provider and there are plenty of CDN providers available.

After this, there are two main ways of working with a CDN. A Push zone and a Pull zone.

In a Pull zone, your CDN mirrors your server, copying everything that’s on it and serving a copy.

Whereas, In a push zone, you need to upload your files directly to your CDN provider and your provider serves those requested files or content to users on their browser.

Pull zone is the simplest and cheapest way to connect CDN with your WordPress website. You can set one of these with your CDN provider and point it at your domain. After pointing, it will pull all the files from your server and maintain a copy of the same.

After this, it will give you an URL from which you can access these files. Your URL will look something like mk124.yourcdn.com/yoursite/

Usually after an hour, you will be able to access all your files on this URL the same as if you look at your own site.

So, now the image that exists on your site as

mysite.com/wp-content/uploads/image.jpg

Can be accessed as

mk124.yourcdn.com/yoursite/wp-content/uploads/image.jpg

Step 2: change your WordPress settings at CDN’s copy

After the completion of step1 , all the resources( images, stylesheets & scripts ) will be available on the CDN.

The last & the most important step is to make all your posts load those images from the CDN and not your server . There are many ways to get this done.

Either you can go through a regular update and change the resources on every post manually or you can add a small function as below in your functions.php file

By applying this fix, all your uploads will now be loaded  from the CDN instead of your server.

Just in case, you decide to get back to old server and not CDN, delete those lines from your functions.php file and all your images will load from your own server again.

If you are not using above technique then there is a plugin called CDN Enabler, a light-weight WordPress CDN plugin to link your asset to a content delivery network. Using this plugin is the easiest way to integrate any CDN with your WP website. It quickly integrates CDN to your WP website and has an ability to set included directories, excluded extensions and enables relative paths and HTTP connections.

Following are the steps of how to integrate WordPress CDN with CDN enabler

  • Create a Pull zone in the CDN dashboard
  • Install the CDN enabler plugin
  • Activate the plugin and click on the settings
  • Enter the CDN URL or Zonealias in the CDN enabler settings (You can find URL in the CDN dashboard)
  • Save the settings and verify in the HTML code if your assets are loading from the CDN

CDN with WordPress can help reduce site latency and speed up website for users worldwide ultimately reducing the load on your server. Check out our complete guide on how to speed up WP website.

1

Enjoyed the article?

Press 💚 below and join the other 13,000+ getting valuable updates from this blog.

blog gdpr GDPR Plugin

How to make your WordPress website GDPR Compliant


July 4, 2018 6:41 AM

blog live chat software

We ditched ZOPIM for Chatra


April 28, 2018 6:45 AM

blog Uncategorized wordpress wordpress security wordpress updates

How To Secure Your WordPress website


April 27, 2018 6:33 AM

blog plugins wordpress wordpress updates

How to update WordPress plugin properly


March 27, 2018 10:58 AM

blog plugins wordpress wordpress updates

What are automatic WordPress updates and how to turn them on


March 26, 2018 1:46 PM

Get Free Site Analysis

Want us to analyze your site first and then use our services? No worries. Just fill out the form to the right and we will be happy to send you a free report about your current website.