I'm using mod_pagespeed with mod_cache.

When mod_pagespeed is off and mod_cache is off I see the following header:


When mod_pagespeed is on and mod_cache is off, I see the following header on the response:

cache-control:max-age=0, no-cache, must-revalidate

As expected pagespeed has rewritten the cache-control.

However, when mod_pagespeed is on and mod_cache is on I see the following:


According to the docs:

"By default, PageSpeed serves all HTML with Cache-Control: no-cache, max-age=0 because the transformations made to the page may not be cacheable for extended periods of time."

Why is the html being served as cacheable when mod_pagespeed and mod_cache is enabled?


There appears to be a bug when running mod_pagespeed with Apache Httpd 2.4.23 running mod_cache.

For some reason mod_pagespeed does not rewrite the cache headers which leaves the html publically cacheable.

The workaround I used was to have virtualhost on port 81 running as a caching server with no pagespeed.

<VirtualHost *:81>
ProxyPass / ajp://tomcat-ipaddress:8009/
ProxyPassReverse / https://final-hostname/
ModPagespeed off
RemoteIPHeader X-Forwarded-For
CacheEnable disk /
CacheHeader on

On virtualhost 443 or 80, you can then proxy the host on 81.

 <VirtualHost _default_:443>
 ProxyPass / http://localhost:81/
 ProxyPreserveHost On
 ModPagespeed on
 ProxyPassReverse / https://final-hostname/
|improve this answer|||||

Because by default mod_cache runs in quick handler mode:


which means it touches the response "last", after mod_pagespeed has performed its transformations.

Use the

CacheQuickHandler off
AddOutputFilterByType ... 

example to order filters as appropriate.

|improve this answer|||||
  • This doesn't make sense. If pagespeed acts first then it will already have changed the cache-control to no-cache and then mod_cache will not attempt to cache. – DD. Sep 15 '16 at 6:47
  • Pagespeed isnt seeing the request, it was already cached. Try making sure the ondisk cache is deleted, then have both on, then issue a request. – Jonah Benton Sep 15 '16 at 10:28
  • ...how are you making these assumptions? It is seeing the requests as they are being optimised. Also the optimisations are browser specific (e.g. chrome gets webp). The pagespeed optimisations should never be cached as pagespeed is supposed to modify the cache header. – DD. Sep 15 '16 at 11:36
  • no assumptions, lots of experience with mod_cache. Are there instances of the urls being visited in the mod_cache cache? What do logs report about the order in which the filters are being run? – Jonah Benton Sep 15 '16 at 13:00
  • What problem is being solved by using modcache and pagespeed together? – Jonah Benton Sep 15 '16 at 13:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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