Open rosell-dk opened 6 years ago
Its convenient with a header for debugging. In order to also get a header when image is routed to already converted image, we can instead add the headers in the .htaccess.
1) We set env in the two RewriteRules, like this: [E=webpexisting:1] and [E=webpnew:1] 2) We add the headers conditionally, like this:
<IfModule mod_headers.c>
Header append X-WebP-Express "Routed to existing converted image" env=REDIRECT_webpexisting
Header append X-WebP-Express "Routed to image converter" env=REDIRECT_webpnew
</IfModule>
I was in doubt whether to add the "X-" in front of the header.
Here is a discussion on that subject: https://stackoverflow.com/questions/3561381/custom-http-headers-naming-conventions
Using "X-" is depreciated, but not forbidden. I'm with G-Mac saying "Just as there are many kids that will never end up as professional athletes, many custom headers will never end up as standards. I'm inclined to keep the "X-" on those"
It should also warn if mod_headers isn't enabled - ie by testing if the response has the Vary:Accept header
If the first part of the rewrite rules should fail (the part that looks for a converted image), the converter will be called each time an image is requested. - A bad situation.
Proposal: We can provide a test button. Clicking it sends an ajax request to the server. The response header is then inspected (https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/getResponseHeader). If it contains a custom header "X-WebP-Convert: yes" or similar (that we must add to WebPConvertAndServe), then the converter has been activated. Otherwise not. We can then show a message indicating if the webp was taken from cache or not.