PrimeFaces 6.0 does not cache images on the client side
Headers look good. This suggests that something in query string parameters changes from request to request. This would also be interpreted as a brand new resource and thus bust the caching even though the base URI (the part before URL query string separator ?
) is exactly the same.
And indeed, PrimeFaces 6.0 has changed the way how the pfdrid
query string parameter is generated. It has become a completely random UUID
which changes every time when the HTML <img src>
is rendered. See also line 59 of PF 6.0 source code. In PrimeFaces 5.3, it was encrypted based on EL expression string and thus guaranteed to be the same across requests as long as the EL expression string is the same. See also line 53 of PF 5.3 source code.
The change was introduced by Cagatay without a reference to an issue ticket. So it remains unclear why exactly this change was done. But after all it doesn't offer the client the opportunity anymore to cache the dynamic content and would thus actually decrease performance in both ends. This is definitely worth an issue ticket at PrimeFaces, so I created one: issue 1765.
I'm not seeing a clean way to solve this other than hacking the PrimeFaces source code. Your best bet is to replace the <p:graphicImage>
by a <h:graphicImage>
with a "plain vanilla servlet", or if you happen to use JSF utility library OmniFaces, then the <o:graphicImage>
with a simple bean. Those approaches are already detailed in this related Q&A: Show image as byte[] from database as graphic image in JSF page.
Update: as per issue 1765, it has been fixed for PrimeFaces 6.1.