StrongCaching file images but not resources


I have setup a Apache > Varnish > Plone 5.2.4 Zeocluster. Plone Caching is enabled and all setup and running. I want to StrongCache "File and image resources" but only images. That ruleset annoying bundles JS/CSS with it which causes problems when trying to login.

How do I StrongCache images but not other files? Is the only way going to be to use apache to target and set the headers on images?

Thank you in advance.

Well I got all images caching aggressively now with an apache 2.4 line. I have the "File and image resources" set to moderate caching. I added this rule below to my apache plone.conf file.

Header set Cache-Control "max-age=86400, proxy-revalidate, public" "expr=%{REQUEST_URI} =~ /.*(.png|.jpg|.gif)/"

I still have to put another condition to only do this cache on images with the header value X-Cache-Rule: plone.resource. Then should be golden.

This apache 2.4 rule after my rewrites is working great. All images from zope, file system, diazo theme, are now aggressively cached for the day. All css and js is handled via plone, so no login caching issues anymore.

Header set Cache-Control "max-age=86400, proxy-revalidate, public" "expr= resp('X-Cache-Rule') == 'plone.resource' && %{REQUEST_URI} =~ /.*(.png|.jpg|.gif)/"


Another way to do it is on Varnish config file:

sub vcl_backend_response {
    if (bereq.url ~ \.(png|jpg|gif)$) {
        set beresp.http.Cache-Control = "max-age=86400, proxy-revalidate, public";

Works for Apache, NGINX, or accessing directly by Varnish.

1 Like