MaxCDN is a reputed content delivery network (CDN) service which lets you serve images and other static files from different servers in different locations across the world. This reduces the page load time significantly and improves the search result ranking.
MaxCDN is cheaper and easy to configure with all types of website platforms including the WordPress. They provide a detailed step-by-step guide to set up its CDN service with your blog. You need to create a PULL zone at MaxCDN admin panel and install either W3Total Cache or WP Super Cache at your WordPress blog. There should not be any problem in configuring your CDN with WordPress through those plugins. But what, if you want to configure MaxCDN with your WordPress blog without any plugin?
Recently, I decided to purchase MaxCDN for our blog TechTipsApp.Com to serve images from a subdomain. After going through the setup process at MaxCDN admin panel, I needed to install any one of the above cache plugins. Here the problem raised for me.
This blog is hosted on SiteGround, a reputed web hosting service. It is the only web hosting company which provides Memcache service with the shared hosting plan. It also has 3 layer caching service which gives you a better performance.
SiteGround has its own caching plugin which is configured according to their servers. They always recommend to use their own caching extension to get the better performance than this by other caching plugins like W3TC or WP Super Cache. And it happens what they say.
As I was already using the SiteGround’s cache plugin, installing anyone of the the above cache plugins could conflict with each other. I contacted with the MaxCDN support and they told me that there is no way to use its service without having those plugin installed with the WordPress. I was just upset as I’ve already paid for the MaxCDN plan. Then I contacted with the SiteGround support team and described the whole thing. After taking a while they still recommended their own plugin SGCachePress and advised to avoid using other cache plugins. They also suggested not to use both SGCachePress and W3TC / WP Super Cache at the same time. So, I had two choices:
- Compromising with the caching performance and using the third party cache plugin to use MaxCDN
- Not using the MaxCDN.
But I wanted both. After going through some testing phases, I found out a very easy way to use MaxCDN service in WordPress without any plugin.
How to Configure MaxCDN in WordPress without any Plugin
All you need to do for this tricky tweak is changing the media setting at your WordPress admin panel and running a simple SQL query at your WordPress database. Here is how to do that.
Login to your WordPress admin panel and expand the ‘Settings’ option from the left sidebar and click on the item ‘Media’. Up to WP version 3.4, this settings page used to allow you configuring the default uploading path and the image URL path. But from the WP version 3.5, this feature has been withdrawn. I don’t know about the exact reason behind that but you can still bring back that feature at your current WordPress version by using this simple plugin.
Once you installed that plugin, you can see the options for changing the uploading path and the full URL path at the media settings page.
Now, notice that the ‘Store uploads in this folder’ filed is like this: wp-content > uploads, keep the default uploading path as it is. The MaxCDN automatically caches the contents from that directory. What you need to change here is the ‘Full URL path to files’ field. Just replace the domain name with your subdomain(MaxCDN pull zone).
Once you complete the modification, save the settings and you can then uninstall the plugin. Don’t worry, the settings you’ve done won’t be removed until you completely make the fields empty.
Now, whenever you upload any image or file using the WordPress media uploader, it will be uploaded at the ‘uploads’ directory and the source path will be replaced with the URL that you mentioned at your media settings page. It means that the images will be served through the subdomain which is hosted by MaxCDN.
To serve the old images from the subdomain hosted by MaxCDN, go through the following workarounds.
Open phpMyAdmin from your hosting cPanel and select the database. Now, click on the SQL tab and run the following queries.
UPDATE wp_posts SET post_content = REPLACE(post_content,'http://www.yourdomain.com/wp-content/uploads/','http://cdn.yourdomain.com/wp-content/uploads/')
UPDATE wp_posts SET guid = REPLACE(guid,'http://www.yourdomain.com/wp-content/uploads/','http://cdn.yourdomain.com/wp-content/uploads/')
Don’t forget to replace ‘cdn’ with your own subdomain. You are done! All the images are now served from the subdomain via MaxCDN.
Have any thing to add to this story? Do share with us at the comment section.