CSS Caching Issues With Pagespeed

We came across a weird situation at work which we hadn’t seen before where changes to CSS files weren’t being reflected on our Apache served website. Why? The Apache module: Page Speed.

This isn’t a criticism of that - in fact, it’s often said that using that module can sometimes increase the speed of your site 4x. This is a warning, however, and some tips on how to get round the fact that it will aggressively cache your files, and might catch you out!

Assuming you do have Page Speed installed in your Apache website, you can turn off the whole module and instantly see whether caching is causing your issue.

Finding Your Apache Installation Folder

In my installation, I can find the Apache configuration files at this location: /etc/apache2/ but on other distros, it might be: /etc/httpd, so experiment with your site.

Is Page Speed Installed?

Starting from the location of your Apache installation, we want to look into the mods-available folder and if you see the Page Speed configuration file, you have it installed.

1
2
$ cd mods-available
$ ls -l pagespeed.conf

Assuming it is, let’s switch it off.

1
$ sudo nano pagespeed.conf

Now look for the line which will probably say ModPagespeed on and replace on with off. Save the file.

Lastly, restart Apache

1
$ sudo service apache2 restart

If you visit your site, should Page Speed have been the cause of caching your files, it shouldn’t be now.

Determining the Cache Folder

Still inside the mods-available folder mentioned above, you can quickly find out which folder is being used to cache files with this command:

1
2
3
/etc/apache2/mods-available$ grep ModPagespeedFileCachePath pagespeed.conf
# The ModPagespeedFileCachePath directory must exist and be writable
ModPagespeedFileCachePath "/var/cache/mod_pagespeed/"

Make a note of that folder because you can use it to empty the cache, later.

Turning Page Speed off With a URL

This is a handy URL you can use to switch off Page Speed. From what I can tell, it doesn’t empty the cache, but stops some of the bundling that Page Speed does. Try it and see; visit:

1
https://yoursite.com?ModPagespeed=off

Emptying the Cache

Once you know where the files are being cached (see Determining the Cache Folder), there is an easy way to tell Page Speed to empty the cache. Either create or refresh a named file in that location, which you can do like this:

1
$ sudo touch /var/cache/mod_pagespeed/cache.flush

Remember to replace the folder path with your cache folder, if necessary. touch, if you wasn’t aware, is a useful command that will either make a file or reset its timestamp to the current date and time.

Assuming Page Speed is running, a short while later (under a minute), and the whole cache should be emptied ready for your to test your website again.


Hi! Did you find this useful or interesting? I have an email list coming soon, but in the meantime, if you ready anything you fancy chatting about, I would love to hear from you. You can contact me here or at stephen ‘at’ logicalmoon.com