Google recently announced that they will be using site speed as part of their search rankings.
I have been meaning to look into my blog page speed for some time, and this event spurred me to finally get my ass in gear. I installed Google’s Page Speed application, and started testing my blog pages.
One of the key optimization suggestions that kept coming up was –
Parallelize downloads across hostnames
Art is another passion of mine, and I use many images on my blog. As a result, many of my blog pages have 50 or more image links.
Different browsers have different limits on the number of resources (e.g. images) they can download simultaneously from a given domain. However, all browsers have a limit.
Since all of my image links are from the same domain, much of the download is serialized.
To optimize performance, I can spread my blog image links across multiple domains, which will increase the number of images that a browser can download in parallel. The good news is that sub-domain names can also be used to enable parallel downloads. Therefore, you need not buy more domain names just to enable this functionality.
Note however, that using too many domain names will cause performance to degrade.
Our rule of thumb is to increase the number of parallel downloads by using at least two, but no more than four hostnames. Once again, this underscores the number one rule for improving response times: reduce the number of components in the page.
~~[Maximizing Parallel Downloads in the Carpool Lane from the Yahoo! User Interface group]
Plugin for parallelizing image downloads
Since parallel downloads seem like a useful feature, I have added it into my Shiba Media Library plugin. To access this new functionality –
- Go into Media >> Media Tools.
- The input text area should start out with your blog base uploads directory. Enter in your other parallel domains – one in each line.
- You may choose to parallelize single or multiple posts (e.g. your blog front-page, category page, or tag page). If your theme uses excerpts when there are multiple posts, then limiting the parallel download process to just single pages will save on processing time and increase page speed.
Note – it is important that each entry points to exactly the same location because the plugin will simply find all image links that match the first domain name, and replace it with the subsequent domain names.
I have found that it is most efficient to point to the WordPress wp-content directory because most image resources are stored there. For example, my parallel download domains are as follows –
http://www.shibashake.com/wordpress-theme/wp-content http://wordpress.shibashake.com/wp-content http://wordpress-images.shibashake.com
In general, it is best to only run the_content plugin filters ONLY when necessary.
Adding parallel downloads to your theme
The parallel downloads function described above only operates on your post content. If you want to extend image parallelization to your post thumbnail images, and comment images, you will need to inject the parallel downloads function into your theme files (most likely index.php and comments.php).
Add parallel downloads to your theme –
- Look for the get_the_post_thumbnail function call in your theme index.php file.
- Replace the get_the_post_thumbnail statement with a variation of the code below. Some tweaks may be necessary depending on how your theme uses post thumbnails.
<?php global $shiba_mlib; $thumbnail = get_the_post_thumbnail(); if (is_object($shiba_mlib) && method_exists($shiba_mlib, 'parallelize_link')) echo $shiba_mlib->parallelize_link($thumbnail); else echo $thumbnail; ?>
<?php global $shiba_mlib; $avatar = get_avatar( $comment, 42 ); if (is_object($shiba_mlib) && method_exists($shiba_mlib, 'parallelize_link')) { echo $shiba_mlib->parallelize_link($avatar); } else echo $avatar; ?>
You are done!
Let me know if you run into any problems with this new plugin update.