Since I originally moved my blog to the Jekyll platform, I’ve been looking for several ways to push the performance of my website further.
Over the last couple of months, I’ve been exploring several content distribution networks for my new web course Extreme Website Performance, such as CloudFlare and Amazon’s CloudFront, as well as forgoing a CDN altogether and focusing on reducing the number of network requests used (and therefore taking the bottleneck away from the distribution servers).
Currently, if you take a look at the source code of my website, you’ll see something peculiar– a severe lack of indentation and several, inlined Base 64 and WebP images. For example, here’s a snippet of my website’s source HTML from the home page.
<div class="photo"> <img src="data:image/webp;base64,UklGRg...AAA="/> <h2><a href="/blog/multiple-gradients-css">Multiple Gradients in CSS</a></h2> <span>20 May 2013</span> </div>
Obviously, it would be counter productive for me to design my HTML pages without any indentation– it would be a nightmare to manage opening and closing brackets. Rather, I’ve enabled mod_pagespeed by Google on my server, which does this minification for me automatically.
Installing mod_pagspeed with the default parameters takes a little less than a minute. You can view the instructions to install the optimization system for your respective application server on the Google website. As mentioned previously, mod_pagespeed is available for the Apache and nginx servers.
Out of the box, mod_pagespeed is ready to go and is immediately enabled for all of your HTTP websites, but a little bit of configuration you can do. You can find all of the configuration options and filters in the documentation.
If you’d like to disable mod_pagespeed globally and only enable it per-virtual-host, you can do so by editing the
pagespeed.conf file. The location of this file depends on your server and operating system (the combinations of OS/Server and respective file locations are available in the documentation), but for Ubuntu and Debian servers with Apache, the file will usually be located in
pagespeed.conf file, you can specify global filters or enable/disable the optimization system entirely. To disable mod_pagespeed, simply add a new line in the configuration file:
This single line will disable mod_pagespeed globally, but still allow you to enable it per-site.
To do so, edit your website’s virtual host configuration (located in
/etc/apache2/sites-available for Apache/Ubuntu/Debian users) and add a new line, similar to what you did previously to globally disable mod_pagespeed–
Other options include the
ModPagespeedEnableFilters configuration line item, which allows you to enable additional optimization filters, such as the GIF/PNG to WebP image converter.
Personally, I have three other filters enabled in addition to the defaults–
The first and last filters in the list above automatically convert JPG, GIF, and PNG images to WebP when applicable and a supported browser is being used by the visitor. If you’re using a supported browser, such as Google Chrome, you can see this for yourself by right clicking any image and viewing the source of the web page or copying the URL of the image.
collapse_whitespace filter, while slightly more “dangerous” due to the fact that it significantly modifies the webpage itself with the potential to improperly remove whitespace, also reduces the file size of the HTML slightly.