Category Archives: servers

mod pagespeed causes google checkout problems on dreamhost vps

If you’re running a vps (virtual private server), an oscommerce-based cart, a 3rd party google checkout payment module that requires zend optimizer and happen to be with a hosting company that offers ‘web site optimizations’ … (yeah I know, pretty select situation), make sure to take a close look at the web hosting control panel because ‘page speed optimization defaults’ may include the apache module mod_pagespeed, Google’s own bash at making your sites go faster.

A recent job I had was to fix a failing google checkout callback for a client who runs a site on a dreamhost vps. After a lot of of tests and removing various caching and compression features, plus an investigation into php compiled via fastcgi (that I wouldn’t recommend to anyone), I noticed that all the stylesheets were getting linked together in the page source code of the site. For example, a cre loaded site running product page tabs and a social media box might look: lesheet.css+tabs,

Note ‘pagespeed’ in the url – this is an indicator that you too have google’s mod_pagespeed running on your server.

It was easy to deactivate the Page Speed Optimization module (which includes mod_pagespeed – remove a tick in a box) but man, it took some hunting down (mainly because I wasted time looking at the ‘complicated’ when it would be better to check the ‘obvious.’)

You can read a whole lot more about Google’s ‘Page Speed Optimization’ suite of tools (which includes the apache mod_pagespeed) from this url: code [dot] google [dot] com/speed/page-speed/

Here is a list of some of the filters it uses, to give you an idea of what it might do to for your site:

ModPagespeedEnableFilters combine_css
ModPagespeedEnableFilters rewrite_css,rewrite_javascript
ModPagespeedEnableFilters inline_css,inline_javascript
ModPagespeedEnableFilters rewrite_images
ModPagespeedEnableFilters insert_img_dimensions
ModPagespeedEnableFilters remove_comments
ModPagespeedEnableFilters extend_cache
ModPagespeedEnableFilters remove_quotes

speed up your site – set expiration in cache control

Another useful Apache utility called mod_headers can be used to set an expiration date in the future of files like images and static html pages. This means that rather than loading image files or unchanging html code every time you visit a site, a check will be made in the cache of your browser to see if there is already an existing copy of the file requested. If the file is still ‘fresh’ – ie within the period specified by the expiration, the cached version of the file will be used and no ‘refresh’ call will be made to the host server.

Your server needs to have mod_headers enabled before being able to use these directives. You can add this code to your root htaccess file, or http.conf / vhosts.conf if you have access to those.

<IfModule mod_headers.c>
#cache html and htm files for one day   
<FilesMatch ".(html|htm)$">   
Header set Cache-Control "max-age=43200"  
#cache css, javascript and text files for one week   
<FilesMatch ".(js|css|txt)$">   
Header set Cache-Control "max-age=604800"  
#cache flash and images for one month   
<FilesMatch ".(flv|swf|ico|gif|jpg|jpeg|png|pdf|swf)$">   
Header set Cache-Control "max-age=2592000"  
#disable cache for script files   
<FilesMatch ".(pl|php|cgi|spl|scgi|fcgi)$">   
Header unset Cache-Control   

When changing conf files on an Apache server, remember to Apply Changes and restart the Apache server for the directives to take effect.

Another approach is to use ExpiresByType commands in the htaccess file:

# turn on the module for this directory
    ExpiresActive on
# set default
    ExpiresDefault "access plus 24 hours"
    ExpiresByType image/jpg "access plus 1 months"
    ExpiresByType image/gif "access plus 1 months"
    ExpiresByType image/jpeg "access plus 1 months"
    ExpiresByType image/png "access plus 1 months"
    ExpiresByType image/x-icon "access plus 1 months"
    ExpiresByType text/css "access plus 1 months"
    ExpiresByType text/javascript "access plus 1 months"
    ExpiresByType application/javascript "access plus 1 months"
    ExpiresByType application/x-shockwave-flash "access plus 1 months"

Final tip: set eTags to null using:

Header unset ETag
FileETag None

speed up your site – use compression

If your server is running Apache 2.xx then mod_deflate can be used to compress certain file types, which will give a real boost in loading speed as the client’s browser will be uncompressing the content, rather than the server carrying the full load.

To enable mod_deflate, add the following to root htaccess (or ideally http.conf or if on a virtual server, vhosts.conf)

<IfModule mod_deflate.c>
<FilesMatch ".(js|css)$">
SetOutputFilter DEFLATE

This snippet of code compresses javascript and css for unpacking by the visitor’s browser.

If your server is running Apache 1.x then mod_gzip can be used. This can be added to the root htaccess file.

<IfModule mod_gzip.c>   
    mod_gzip_on         Yes   
    mod_gzip_dechunk    Yes   
    mod_gzip_item_include file          .(html?|txt|css|js|php|pl)$   
    mod_gzip_item_include handler       ^cgi-script$   
    mod_gzip_item_include mime      ^text.*   
    mod_gzip_item_include mime      ^application/x-javascript.*   
    mod_gzip_item_exclude mime      ^image.*   
    mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*   

You might also like to enable Gzip Compression through Admin/Configuration/Gzip Compression, set at 9.