Recently installed Google's plugin mod_pagespeed and I want to use it exclusively to address image optimization.

So far the result frim Pagespeed insights has been hit or miss. Half the time it does fine, the other half it complains that I should "Leverage browser caching for the following cacheable resources." - with a long list of nearly every image on my home page cached at the 5 minute default.

Now I've read that this can sometimes happen if the module hasn't completely finished rendering the cached version and that it will serve a temporary image with a short cache in the interim. But I can't understand why that would be the case since the images have not changed and they are the same images it only just 10 minutes ago said were fine.

So as far as I can see:

  • the images are there in the cache and being served without issue
  • the image files have not changed so the cache should remain valid

I am running Apache 2.4.18 and mod_pagespeed The config file pagespeed.conf is configured with the following two lines toward the bottom before the <Location> block:

ModPagespeedRewriteLevel PassThrough
ModPagespeedEnableFilters rewrite_images,extend_cache_images

Can anyone suggest an explanation for what looks to be a persistently expiring cache?

  • I haven't played with Google's pagespeed plugin, but read my post here on mod_expires and more. I think this will solve your problem.
    – Trae Abell
    Commented Mar 14, 2017 at 12:28
  • @TraeAbell - No that doesn't help. pagespeed takes over expires headers on it's cache files once activated and I already had those set up anyway. I ended up just giving up on it and writing my own image optimization script. Commented Mar 14, 2017 at 14:13

1 Answer 1


I have found that mod_pagespeed serves images and other resources with a cache expiration of 5 minutes if they are not available in its cache directory (yet). Also, after restarting the Apache webserver it takes a while until mod_pagespeed regains its maximum efficiency.

It may help to delete and recreate the cache directory:

sudo mv /var/cache/mod_pagespeed /var/cache/mod_pagespeed.del
sudo rm -rf /var/cache/mod_pagespeed.del/
sudo mkdir /var/cache/mod_pagespeed
sudo chown www-data:root /var/cache/mod_pagespeed/
sudo service apache2 restart

To determine the current size of mod_pagespeed's cache directory:

du -hs /var/cache/mod_pagespeed/

To increase the size of the disk cache from 100 MB (default) to 10 GB in mod_pagespeed's configuration file /etc/apache2/mods-enabled/pagespeed.conf:

ModPagespeedFileCacheSizeKb          10240000
  • Thanks Helge but the cache is already built so it's nothing to do with initial creation - as mentioned in the second paragraph of my question. Disk cache size on the other hand may be involved so good call there. Commented Aug 29, 2017 at 15:54
  • Cache size was the issue for us, coupled with the fact it gets cleared down on a schedule rather than on a LRU/on demand basis which made page performance look more random.
    – Matt
    Commented Mar 1, 2018 at 12:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.