0

I'm using mod_pagespeed with mod_cache.

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

cache-control:public,max-age=7200,must-revalidate

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:

cache-control:public,max-age=7200,must-revalidate

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?

2 Answers 2

1

There appears to be a bug when running mod_pagespeed 1.11.33.2-0 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 </VirtualHost> 

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/ 
-1

Because by default mod_cache runs in quick handler mode:

http://httpd.apache.org/docs/current/mod/mod_cache.html#cachequickhandler

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.

12
  • 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. Commented Sep 15, 2016 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. Commented Sep 15, 2016 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. Commented Sep 15, 2016 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? Commented Sep 15, 2016 at 13:00
  • What problem is being solved by using modcache and pagespeed together? Commented Sep 15, 2016 at 13:24

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.