Wordpress

Optimize WordPress site load time by hosting images on a subdomain !

WordPress is what that powers almost every dynamic blog sites on the web.And on saying dynamic it is obvious that every page load needs some process to be done.This requires more CPU usage and also takes some time to generate the page, especially when the page is full of dynamic content.This is the greatest challenge faced by web designers using WordPress, and not just this almost all CMS and blogging systems have same problem to overcome.

WordPress being opensource, many developers and programmers provide some Plugins and tweaks to optimize wordpress sites.But it does not make it lightning fast.And is to be accepted too.I receive many mails asking for some better tweak to improve the load time of WP site.Any tweak can do only its part and there are much other factors that slow the page load.One such thing is Images.

WordPress, by default stores the uploaded images and media in domain.com/wp-contents/uploads.This being a directory on the root domain, is loaded along with all other content.Also uploads on different domain too are not allowed.Here is where we make use of Sub domains.By hosting images in a sub domain, the priority of images is lowered and thus the page is loaded which is then followed by the images on it.Just follow the steps below to optimize your WordPress blog.

Create a Sub-Domain for your images

You would notice all of Technostreak’s images are stored in img.technostreak.com/… the similar way you could decide what your image sub domain would be called as. Like images.domain.com (or) img.domain.com (or) uploads.domain.com or any thing for the cause.

Creating Subdomain differs with the host you use.If you host provides cPanel, then you will need to go to Subdomains under the Domains section.Give your sub domain a desired name and change document root only if necessary.(usually accepting what is generated does it.)

Change WordPress default Upload directory

  • Head to Settings>>Media (or Settings>>Miscellaneous if you are using older version of WordPress).
  • Under Uploading Files Change the values for Store uploads in this folder and Full Path to files.
  • Make sure the values are the same as how you created the subdomain.

Move images from old directory to the subdomain

With a desktop FTP manager or using the one on the cPanel, either Move the files from the directory wp-content/uploads to the sub domain directory, or Download the whole folder and then upload it to the sub domain directory.

Update your old posts to load image from new location

You must sure change the image src in tags as you have moved the images to another location.But changing one by one is not possible if you have oceans of old posts.Here comes SQL query to the rescue! one query does it all, changing the image source in every one of your post.

  • Go to phpMyAdmin where you manage all your WordPress database.You may find the link to it in your cPanel.
  • Once in, Select the database to work with.Select the name of your WordPress database from the list on left.
  • Move to the SQL tab.
  • In the big white box, paste the code given below here.

UPDATE wp_posts SET guid = REPLACE(guid,’http://www.yourdomain.com/wp-content/uploads/’,'http://img.yourdomain.com/’)

**Remember to change yourdomain.com to your original domain name and also change img.yourdomain.com with the subdomain you created.

Notify Search engines about your change of image directory

It is a important action to be done on your side.Search engines would have crawled on your images and if it is missing now all your crawled images will b removed from the list.To prevent this just tell engines that they have moved to another location by a simple tweak on .htaccess file.

  • On your main directory of WordPress installation, you would find this .htaccess file.
  • Back it up before making changes.
  • Open it with a text editor like Notepad.
  • In the file, before the start of WordPress Block paste the statement of code  given below .

RedirectMatch 301 ^/wp-content/uploads/(.*)$ http://img.yourdomain.com/$1

**Change the subdomain name in the code.Dont change the characters after the slash.The filename must be .htaccess only.No text before the period.

What else? Sit back and watch you site load faster than before!Share this Post and also subscribe to our Blog!
Leave Comments!

About the Author

Tharun is a bit attracted towards computers and stuff.He loves to blog,share and know more about computers and technologies.He shares what he feels is something good on this site...Stay connected.
Tharun is on: Facebook , Google+ , Twitter

0 comments