Page load time is an important metric for Google search ranking. The webpages with better loading time will rank better in the Google SERPS. In some previous articles, I’ve described about how to reduce the page load time of your WordPress blog [ 1. Speed Up Blog Improve Page Load Time 2. Install Contact Page Without Any Plugin3. Reduce Page Load Time ] . Another issue is still yet to discuss that effectively participate in your page performance. By default the images of your site are hosted in the same domain. This slow downs your page speed. Because, almost all the browsers create maximum two-four connections when downloading a page from the web server. So if your pages contain more than one images then it is wise to host those images in another domain so that the browser can download the images in parallel with your main domain. WordPress does not support hosting images in different domain. But fortunately, it supports and allows you to host images in a subdomain. This article is about how to host your website post images in a subdomain along with the old images that were hosted in the main domain.
Create a Subdomain for your site
In order to get your subdomain you’ve to log-in to your domain control panel. Point to Subdomains and create your subdomain, provided your domain resides under /public_html/. Note: The facility depends on your hosting provider. So if you are unable to create a subdomain then contact your hosting provider.
Change default image uploading folder in WordPress
This step involves in setting WordPress to change the default uploading folder for the post images. log-in to your WordPress dashboard. Click on
“Miscellaneous” “Media” under “Settings” from left side of the dashboard.
Fill up the fields as follows: Store uploads in this folder : images Full URL path to files : http://images.yourdomain.com
Click on “Save Changes”. Now whenever you will upload any image to your post, the images will be uploaded in the subdomain http://images.yourdomain.com.
Update the old post images location
You’ve just changed the upload location of your post images. So the images of the new posts will be uploaded in the subdomain. But what about the old post images? Changing the location of all the old images one by one is a stupid job. So at first download all the folders containing the images under /public_html/wp-content/uploads/ from your server. Upload all those folders in the folder /public_html/images/. Now you have to execute a simple SQL query on your database. You can do this from the phpMyAdmin in your domain control panel. Click on phpMyAdmin > select your database from the left side > click on the “SQL” tab. Now put the following query in the box
UPDATE wp_posts SET post_content = REPLACE(post_content,'http://www.yourdomain.com/wp-content/uploads/'
Click on “GO”. This query will replace “http://www.yourdomain.com/wp-content/uploads/” with “http://images.yourdomain.com/” in all the image location URL. To update the images links in the media library run the following sql command:
UPDATE wp_posts SET guid = REPLACE(guid,'http://www.yourdomain.com/wp-content/uploads/','http://images.yourdomain.com/')
Redirect the old images link to to subdomain
You have completed all the task with your site and database. But Google has crawled and indexed your old images. So redirect the old image urls to the new image URLs to let Google know that those images are same. To do so add the following line in your .htaccess file
RedirectMatch 301 ^/wp-content/uploads/(.*)$ http://images.yourdomain.com/$1
Reminder: Backup your .htaccess file before any change. That’s all to set your subdomain as post-images upload location.
Now this is time to tweak your website for better performance with great page load time. You can use various tools to optimize your website as well as you can view the page load times for your pages right from your Google Analytics account.
Any question is always well come. Put your reaction in the comment section.