Mod_pagespeed: clear the cache

The Apache module mod_pagespeed can be used to automatically make web pages faster without effort. It promises a 50% speed boost. I’ve been using for some time and can confirm that there is a definitive speed increase.

But there is a big problem when I update the styling of my blog. When I change the theme css file, I do not see the changes. In the beginning I thought it was caused by the caching plugin I use. But after deactivating the plugin, the problem persisted. Using Ctrl-F5 did not help either. I also opened the CSS in the browser and pressed Ctrl-F5. Nothing worked.

Finally, I understood that mod_pagespeed was responsible for it. So I just needed to clear its cache. Unfortunately it seems to be only possible from the command line. So first open a shell. Then you need to find out where the cache is. It is configured in pagespeed.conf. So either open the file and search for ModPagespeedFileCachePath or execute the following:

# grep "^ *ModPagespeedFileCachePath" /etc/apache2/mods-enabled/pagespeed.conf
    ModPagespeedFileCachePath            "/var/cache/mod_pagespeed/"

Now you need to go to this directory and touch a file (don’t worry if the file doesn’t exist yet, it will be created by touch if it doesn’t already exist), or just touch the file with it’s complete path:

touch /var/cache/mod_pagespeed/cache.flush

You then have to wait for a few second and reload your web page and you’ll see that the new style is used.

Instead of doing all these manual steps, you can do the following:

touch `grep "^ *ModPagespeedFileCachePath" /etc/apache2/mods-enabled/pagespeed.conf | awk ' { print $2; } ' | sed 's/"//g'`/cache.flush

You need to adapt the path to the apache configuration depending on where it is stored e.g. use the following if it is stored in /etc/httpd/conf.d instead of /etc/apache2/mods-enabled:

touch `grep "^ *ModPagespeedFileCachePath" /etc/httpd/conf.d/pagespeed.conf | awk ' { print $2; } ' | sed 's/"//g'`/cache.flush

(thanks Kieran for the hint).

14 thoughts on “Mod_pagespeed: clear the cache

  1. I am having the same problem with my site. I wanted to change the font-size for my posts but it is not showing up on my site. I wish there was a simple way to flush the cache without having to do all of this.


    1. There is a much easier way to resolve this.
      1) rename the CSS file (i.e. template2.css)
      2) at the same change the link for the css in the header to the new name

      Voila – Pagespeed picks up the new css and caches that.

      IF it bothers you to have this name change – just change them back after you’ve loaded the page a couple times.

      1. Hi Eric,

        It is of course possible to keep changing the name of the file so that there is no cached version anymore. But if you use a CMS or something similar, this might be more work than calling a script performing the touch. And if this CSS file is used in different locations it becomes very difficult to rename.

    2. Yes, it’d be great if the pagespeed module provided a simpler way to do it. But at least now that this mechanism was introduced it’s at all possible to do it.

      One thing which could be done is to have a URL which when called created the file. Of course you may want to protect the URL with a username and password so that someone else cannot keep flushing the cache without you knowing.

  2. doesn’t give access for users to touch a file in /var/mod_pagespeed/cache. Any other suggestions besides renaming your css file? I can’t believe this type of thing isn’t easy to do. It is such a PITA not being able to see your style changes without going through a bunch of hoops. Looks like no one “system engineered” this pagespeed module. Sorry, vent over. Just very frustrated.

  3. Here’s the CentOS version

    touch `grep "^ *ModPagespeedFileCachePath" /etc/httpd/conf.d/pagespeed.conf | awk ' { print $2; } ' | sed 's/"//g'`/cache.flush

  4. Hi guys, if you are using WordPress and having issues with this:

    1) Create a custom wordpress plugin that enqueues your custom CSS file
    2) In the enqueue line, append ?ver=1 to the css link
    3) With easy access to your plugin editor, you can simply keep changing the version number. i.e. ?ver=2 and mod_pagespeed will treat it as a new file.

    I have created a simple plugin that enqueues a custom css and custom js file which you can use if you wish:

    1. Sometimes having parameters in the URL makes problem caching the files, so that’s the reason why I’d rather clear the cache manually whenever I modify the CSS files (which doesn’t happen too often anyway).

Leave a Reply

Your email address will not be published. Required fields are marked *