Some companies have set up proxies for caching purposes. This way, if employee A have downloaded an image and employee B requests it, the proxy can deliver the image directly.
Here is how this can go wrong:
1. Employee A is using a browser that supports webp. He requests “image.jpg”, and gets a file with that name, but it is actually a WebP.
2. Employee B is using a browser that does not support webp. He requests “image.jpg”, which the proxie has cached. So he gets a WebP, but that does not work for him, so he sees a blank image.
To prevent such a thing from happening, the server can respond with a “Vary” header, which tells the proxy that the respond varies. Vary:Accept means that the respond depends on the “Accept” request header, which is the one the browser uses to tell the server if it accepts webps or not.
So, to conclude, the Vary header must be set in order to prevent problems in some (larger) companies.
The way that WebP Express sets the header is in the .htaccess.
If you examine the .htaccess, you will find something like this:
# Set Vary:Accept header if we came here by way of our redirect, which set the ADDVARY environment variable
# The purpose is to make proxies and CDNs aware that the response varies with the Accept header
<IfModule mod_headers.c>
<IfModule mod_setenvif.c>
# Apache appends "REDIRECT_" in front of the environment variables defined in mod_rewrite, but LiteSpeed does not
# So, the next lines are for Apache, in order to set environment variables without "REDIRECT_"
SetEnvIf REDIRECT_EXISTING 1 EXISTING=1
SetEnvIf REDIRECT_ADDVARY 1 ADDVARY=1
Header append "Vary" "Accept" env=ADDVARY
# Set X-WebP-Express header for diagnose purposes
Header set "X-WebP-Express" "Redirected directly to existing webp" env=EXISTING
</IfModule>
</IfModule>
But as the code reveals, the functionality depends on two (rather common) Apache modules being installed: “mod_headers” and “mod_setenvif”.
The latter is needed in order to only set the Vary:Accept header when a redirection is taking place. Another rule takes care of setting it when the png/jpeg is requested.
But I now realize that this rather complex code in some cases can be simplified. For example, in the folder where the webps are stored, we do not need all that logic. The above can be reduced to the following:
<IfModule mod_headers.c>
Header append "Vary" "Accept"
</IfModule>
This will remove the dependency to “mod_setenvif”.
Does that change get rid of the warning?