wordpress

Improve WordPress media load times with an Origin Pull CDN

This blog entry describes how you can speed up WordPress media load times by using a CDN (Content Delivery Network). You can serve your static content faster, meaning that your site only has to be concerned with generating dynamic content.

Images, scripts and stylesheets can be automatically hosted by third-party CDNs and served to users without touching your own servers. This can seriously improve your own server loads, and makes a lot of sense!

1.    Choose your CDN provider

The first step is to choose the right CDN provider for you. CloudFlare offers free packages for new starters and there are others available such as AWS CloudFront. There are two main types of CDN “Origin Push” and “Origin Pull”. With this exercise we should use “Origin Pull”.

Once you have signed up and setup your CDN, you will be given a CDN URL like the one shown below:

http://shfh3rha1.cloudfront.net/

This is the URL which will be used to fetch your content. For example: a request for the theme stylesheet would be directed to:

http://shfh3rha1.cloudfront.net/wp-content/themes/{themename}/style.css

The CDN will then check if it has that file path already on its servers and also that the cache time has not expired. If not, it will fetch and store the file from the original domain. Otherwise it serves the content directly itself.

2.    Set Up WordPress to use CDN

WordPress can be configured to use the CDN for certain content. This can be done using a plugin; there are various plugins available but for this example we will use W3 Total Cache.

Install and activate the W3 Total Cache plugin and then inside wp-admin go to:

Performance > CDN

Here you can manage how the CDN works and what content you would like it to host. The most important part is the “Replace site’s host name”; this is where you should paste the CDN URL you were assigned during CDN setup.

cdn_01

Save the new settings and you are ready! W3 Total Cache will automatically replace your domain name with the CDN URL for your chosen content types.

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>