. .
Nov 2010

mod-pagespeed – This is what you need for speed

If you already know us – we are passionate speed fanatics. Every request counts, the last bit can be compressed and most of our files are already cached for a long time in your browser. Why? Because we like faster web sites and if we like something – we support it the best way we can.

There are already posts in our blog where you can get some basics about performance optimizations:

In the first post I already explained how you can use Apache modules to optimize the loading time and size of your web page. But today I read about mod-pagespeed. This module tries to combine all the best practices in one module. Even better than that. A lot of its optimizations are fairly complex to reach if you apply them at web application level.

Want get in touch with some magic? Let’s have a look at the source code of this page (or of the even cleaner homepage).

Features:

Let me explain some of the really cool things:

  • Remove every unused piece of text: whitespace, comments and even attributes and quotes (if the browser don’t require them). I deactivated the module for attributes and quotes because the HTML validator like them
  • Compress every file included in the page: images (it even scales the images down to the specified width and height in the html), Javascript and CSS
  • Inline everything which is worth an embedding: CSS, Javascript and images (yes right: Base64 encoding images). If you look at the source code, try to find our logo
  • Cache everything which cause an unnecessary request like images, CSS and Javascript. But what if you want to update a  file? Isn’t it cached in the browser and not re-fetched? mod-pagespeed has its own cache and creates temporary URLs (which can be long-time cached). If the file is updated the calculated hash didn’t match and a new URL is included in the HTML to re-fetch the file. How cool is that? No more version numbers on any file, … I wrote Java Servlet Filters and included this thing in the build process. Damn complicated and now it is handled on an even higher level.

Good stuff, but isn’t it complicated to install? No.

Installation:

Check for the current version here.

wget https://dl-ssl.google.com/dl/linux/direct/mod-pagespeed-beta_current_amd64.deb
dpkg -i mod-pagespeed-beta_current_amd64.deb

Configure the module at /etc/apache2/available-modules/mod-pagespeed and have a look at my configuration.

 SetOutputFilter MOD_PAGESPEED_OUTPUT_FILTER
 
 ModPagespeed on
 ModPagespeedDomain www.viaboxxsystems.de
 ModPagespeedUrlPrefix "http://www.viaboxxsystems.de/mod_pagespeed/"
 ModPagespeedFileCachePath "/var/mod_pagespeed/cache/"
 ModPagespeedGeneratedFilePrefix "/var/mod_pagespeed/files/"
 
 ModPagespeedRewriteLevel CoreFilters
 
 ModPagespeedEnableFilters collapse_whitespace
 ModPagespeedEnableFilters extend_cache
 ModPagespeedEnableFilters combine_css
 ModPagespeedEnableFilters rewrite_css
 ModPagespeedEnableFilters rewrite_javascript
 ModPagespeedEnableFilters rewrite_images
 ModPagespeedEnableFilters remove_comments
 
 # Enable the following if you don't want to validate your side
 #ModPagespeedEnableFilters elide_attributes
 #ModPagespeedEnableFilters remove_quotes

I don’t want statistics at the moment so I skipped this part in the configuration. You will find an documented file after your installation and can check for the hole configuration options here.

I don’t want statistics at the moment so I skipped this part in the configuration. You will find an documented file after your installation and can check for the hole configuration options here.

Links:

Because I could improve our already improved web page I thing this tool is great. If you haven’t done any optimization it can even save your ass when it comes to load time.

We are your experts:

If you are  stuck or want to learn more about the concepts of web page optimization get in contact with us. We can provide experts which speeds up your page. And using the right modules and configurations in Apache is just one part of it.