plan2net / webp

Create a WebP copy for images (TYPO3 CMS)
GNU General Public License v3.0
60 stars 34 forks source link

RewriteRule does not trigger consistently #16

Closed artur2000 closed 5 years ago

artur2000 commented 5 years ago

Hi, we just tested this great extension and observed a strange behaviour. The KewriteRule triggers only sometimes. Eg. for a page with 4 images the browser randomly gets delivered the .jpg version or the .webp version of each image. Both versions exist in "fileadmin/_processed/../../" directory. It does not depends on the image, each of the images on a page shows this behaviour.

RewriteCond %{HTTP_ACCEPT} image/webp
RewriteCond %{DOCUMENT_ROOT}/$1.$2.webp -f
RewriteRule ^(fileadmin/.+)\.(png|jpg|jpeg)$ $1.$2.webp [T=image/webp,E=accept:1]

Any idea why?

wazum commented 5 years ago

Thanks, nice to hear you like it.

How did you test? The filename is still the same, only the content is different. Can you provide more information, like Apache logs or even an Apache Rewrite log, a browser version, maybe the HTTP headers of each request, etc.?

artur2000 commented 5 years ago

You can see it yourself now after the project went live: https://www.ubc-collection.com/unternehmen/galerie/

On this page there are multiple images. In chrome in developer toolbar=>network tab you can see the "type" of the downladed image. Sometimes it is webp, sometimes jpeg.

wazum commented 5 years ago

This has something to do with caching I guess. A user agent that does not support WebP visits your website and the file is cached (you have a proxy somewhere in between?). Now all the other requests serve the jpg version.

I guess you can fix this with the following Apache setting: Header always set Vary "Accept-Encoding,Accept" that forces to include the Accept header to determine if the cached version of a file can be served.

I had no time to test this yet, so you'll have to figure out the details yourself.

The following lead me to this conclusion: https://www.ubc-collection.com/fileadmin/_processed_/4/e/csm_cbc-duesseldorf-dsh-aussen-01-1080p_c112616b96.jpg Response:

Vary: Accept-Encoding
Content-Type: image/jpeg

and https://www.ubc-collection.com/fileadmin/_processed_/4/e/csm_cbc-duesseldorf-dsh-aussen-01-1080p_c112616b96.jpg?v1 Response:

Vary: Accept-Encoding,Accept
Content-Type: image/webp