PageSpeed has it’s own internal cache which causes problems when used alongside the Varnish Cache reverse proxy. You will need to add a VCL file located here, to your
varnish directory. You will then need to add the following code snippet above your
vcl_recv block in your
pagespeed-requirement.vcl from above will split user-agents in to five groups, each with different support for capabilities such as WebP, Lazy load images and different type of screensize. Be aware that this will also split Varnish Cache up in to 5 different buckets to ensure user-agents with different capabilities are served only from the bucket that stored assets corresponding to those capabilities. This is great for high traffic sites despite the splitting of the cache. High traffic should ensure the caches are populated while also receiving the benefits of user-agent specific optimisations.
If you would prefer higher Varnish Cache hit rates as opposed to user-agent specific optimisations, then you should remove all the logic under
sub pagespeed_capability_detection in
pagespeed-requirement.vcl and replace it with a single line
set req.http.PS-CapabilityList = "fully general optimizations only";
This will only enable optimisations which will work on all user-agents and will not split the cache up in to multiple buckets. This is better for low traffic sites and/or if you wish to maximise cache hit rate, which in turn minimises load on the origin.
pagespeed InPlaceResourceOptimization on;