Mod_Pagespeed – How To Clear Cache For Css & Template Edits

Google’s mod_pagespeed for Apache and Nginx can speed up your website and make it load 10 times faster. The reason for the speed boost is that the mod_pagespeed module minifies and caches everything, storing and loading them from a separate location. This means that when you make changes to your website (eg. by adding a new css class to one of your stylesheets), your changes will not be visible until you clear the mod_pagespeed cache. Doing a browser hard refresh won’t help.


What If I Wait for the Cache to Flush Automatically?

I believe mod_pagespeed does some self flushing after some time. I am not sure of the exact duration, but it can take days for the module to flush its cache and fetch fresh files from the origin. If your changes are important, you might want to look into deleting the cache files manually.

How To Clear the Mod_Pagespeed Cache

I use mod_pagespeed on all my sites, including this one. The first time I encountered this problem was when I changed the css for one of my websites. I cleared the sites cache and did a hard refresh but nothing happened. I googled a little and found some sources (some old) that would give you a code to run in the command line which would create a cache.flush file in the mod_pagespeed directory.

Long story short. It doesn’t work. It probably used to work but it doesn’t work anymore.

So how did I do it?

I went in and deleted the cached css file.

  • Login to your web server via FileZilla or via the command line or whatever medium suits you best.
  • Navigate to this path /var/cache/mod_pagespeed/v3/
  • In this directory, there is one folder each for all your websites on that server.
  • Each site’s folder contains the cached files for that website. The path to the files would be similar to the path for your original files.
  • Simply navigate to the css, javascript, or image file you updated and manually delete it.
  • Note that there can be multiple instances for each file. In my case (index.css) I had <em>A.index.css.pagespeed.cf.Yuhxinj5R.css</em>, and <em>A.index.css.pagespeed.cf.VH8ghklGkxP.css</em>. Your file could appear more than two times. Delete each file that apply.
  • Restart apache (or nginx).
  • When someone loads your site again, mod_pagespeed will cache the new files. If you still don’t see the changes, do a browser hard refresh (CTRL + R) or (CTRL + F5)

Stanley Ume

Hi there, my name is Stanley. I spend most of my time learning new technology and doing freelance web design. If this article helped you, please use the comments box below ?. You can connect with me using the social icons below:

You may also like...

Leave a Reply

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