Archive for the 'Blog Optimization' Category

Blog Optimization – Enabling Mod Deflate

Getting started with Apache Mod Deflate was fairly simple. Like mod concat from the first piece in the Blog Optimization series, it’s just a matter of compiling and installing mod deflate. Mod deflate comes with Apache 2.2, the first step is locating it.

prompt:$ find / -name mod_deflate.c
# change directory (cd) to the location of mod_deflate.c
prompt:$ apxs -i -a -c mod_deflate.c
prompt:$ apachectl configtest
# make sure the syntax is okay
prompt:$ apachectl graceful # restart the server

Now that mod_deflate is enabled, it’s time to configure it. I couldn’t find much information during the research phase on configuring the module. I knew from previous experience that I wanted to gzip, or deflate, all static files. Eventually, I found this post on configuring mod_deflate with cPanel. It was helpful, I modified it slightly to include a few other file types

<Location />
    AddOutputFilterByType DEFLATE text/html text/plain text/xml application/xml application/xhtml+xml text/javascript text/css application/x-javascript application/x-shockwave-flash
</Location>

The Apache 2.2 docs indicate the AddOutputFilterByType directive is deprecated and mod_filter should be used instead, I haven’t had time to play around with mod filter and the Apache 2.2 docs urge caution since it’s not fully tested. If anyone has experience with mod filter, please share in the comments section below.

Mod deflate has done wonders to reduce my bandwidth costs and site performance. On average each request uses 25% less bandwidth than without mod_deflate. Obviously images don’t benefit from gzip compression, but all JavaScript, CSS, HTML and flash files are benefiting by being about 50% smaller in size. For instance, JQuery is about 30.3kb on the server. When it’s delivered using mod_deflate it’s 16kb according to Firebug.

Have a look at some before and after numbers from my server logs.

Day Number
of
visits
Pages Hits Bandwidth
26 Dec 761 3966 12131 242.29 MB
31 Dec 761 4161 12809 196.94 MB

Do you have any blog optimization techniques you are using on your site? Check out my related posts on Blog Bloat and using Mod concat if you interested in optimizing your blog or website.

Blog Optimization – Getting Started with Mod Concat

Following my post on Blog Bloat, I have finally gotten around to installing mod_concat. I asked my hosting provider ServInt to handle the upgrade to Apache 2.2.x, they did it in about 20 mins – thanks guys, you rock!

The actual installation of mod_concat was fairly simple thanks to the included instructions, though it lacked a few of the finer points, like needing to install the module into the Apache modules directory and modifying httpd.conf to include mod_concat, this is easily handled by adding the -i and -a flag. First grab the project out of SVN, then you can compile it.

prompt:$ svn checkout http://modconcat.googlecode.com/svn/trunk/ modconcat-read-only
prompt:$ cd modconcat-read-only/mod_concat
prompt:$ apxs -i -a -c mod_concat.c 
#Make sure the config file is working okay
prompt:$ apachectl configtest
#Then it's safe to restart and use the concat module
prompt:$ apachectl -k graceful

That’s all it takes to get the module working with Apache 2.2.x. I setup a super simple test here to ensure mod_concat is working.

Optimizing WordPress K2 using mod_concat

Getting this Apache module working with WordPress and K2 wasn’t quite as simple as I was hoping. I ended up having to do more customization work than I desired. The issue with K2 is that many of the included JavaScript files, for handling the rolling archives and live search, have a .php extension that includes a gzip directive header. Additionally, the K2 files are nested so deep that mod_concat can’t handle it.

To deal with these short comings, I sourced the K2 JavaScript files and moved them to a root directory. Currently, the files to be concatenated are hard coded into the plugin. Perhaps a future revision will resolve this, however, I am more interested in testing out mod_jsmin and mod_deflate before I get around to this enhancement.

Here is the plugin code I wrote in order to use mod_concat with K2.

<?php
/*
Plugin Name: WP Mod Concat
Description: This plugin leverage the Apache 2.2.x module mod_concat to combine a list of files into a single file
Version: 0.1
Author: Gregory Tomlinson
Author URI: http://gregorytomlinson.com/encoded/
*/
 
remove_action('wp_head', 'wp_print_scripts');
add_action( 'wp_head', 'wp_mod_concat_optimzie' );
 
function wp_mod_concat_optimzie(  $handles = false  ) {
        $base_url = "http://gregorytomlinson.com/js/??";
        $script_files = array("jquery_1_2_6.js", "k2.functions.js", "k2.livesearch.js",  "k2.rollingarchives.js",  "k2.slider.js", "k2.trimmer.js", "swfobject.js" );
 
        echo '<script type="text/javascript" src="'. $base_url . join(",", $script_files) .  '"></script>';
}
?>

By using remove_action(’wp_head’, ‘wp_print_scripts’);, I can stop WordPress from loading JavaScript files. I then replace the head script files with the concatenated version leveraging mod_concat, which produces a script tag that looks like the following.

<script type="text/javascript" src="http://gregorytomlinson.com/js/??jquery_1_2_6.js,k2.functions.js,k2.livesearch.js,k2.rollingarchives.js,k2.slider.js,k2.trimmer.js,swfobject.js"></script>

You can learn more about mod_concat here.

The other drawback to mod_concat is it’s incapable of handling query parameters. I would like to be able to append a ?ver=1.1 in order to handle busting the browser cache, but the current version isn’t able to do this, maybe Ian can fix this :)

That’s all it takes to use mod_concat. It’s probably not the ideal method to use with WordPress and K2, you may consider using PHP Speedy. Dave Artz runs down a list of other concatenation methods in this blog post.

Blog Bloat

A new study analyzing the so-called ‘blog’ format was recently published on Royal Pingdom. Among other things, the study found that many popular blogs exceeded 500kb in page weight.

Long pages with copious amounts of images, links and script files have become synonymous with the blog-style page design and has been replicated across the blogoshere. However, the study concludes that this format may actually prove to be a disservice for blogs.

Optimization experts have long suggested that shorter load times and faster pages make sites more competitive. This belief has largely been discounted by blogs, which typically try and cram as much on the page as possible in order to provide the reader with relevant or interesting content.

The study suggests that disregarding optimization techniques, even for broadband users, actually does a disservice for blogs and leads to frustrated users. This should come as no surprise to any web-savvy individual, but has largely been ignored.

You can measure how well your site or blog performs via the Page Test tool, which was written by Pat Meenan. Check out the results for my blog, here. I scored an impressive 0.2secods to first byte, but a lousy 2.2 seconds until start render. Read the entire study here. How fast are your pages?