Parallel Downloads – Optimize Your Image Links

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.

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 -

  1. Go into Media >> Media Tools.
  2. The input text area should start out with your blog base uploads directory. Enter in your other parallel domains – one in each line.
  3. 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
    
    
  4. 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.
  5. 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;
    ?>
    
  • Look for the get_avatar function call in your theme comments.php file.
  • Replace the get_avatar statement with a variation of the code below. Some tweaks may be necessary depending on how your theme uses gravatar images.
  • <?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.

Related Articles

Comments

  1. says

    Hello – the 2 items I have been looking for help with are increase download parallelization by distributing these requests across multiple hostnames and to use cookie free domains. So I found your blog ;) but i see from the comments that the image parallelization option was removed. Do you have suggestions on how I get started with this. I have a self-hosted wordpress blog. Thanks.

  2. says

    Hello,

    Congratulation on this plugin… truly an asset, for worpdress websites
    Meanwhile, i can’t figure it out where’s the Shiba Media Tools, can you tip me?
    Cause i’ve installed already the 3.6 version… and can tell where it is.

    thanks

    • ShibaShake says

      No. As I understand it, NextGen has its own gallery handling process and functions, whereas the Shiba plugins focus on building from native WordPress objects and functions. Both do similar things but are based on different back-end structures.

Leave a Reply

Your email address will not be published.

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>