Problem/Motivation
When converting images using an image style, to webp (as typical use-case, but I guess it might be the same for other formats), the resulting MIME return type of the image stays the old one:
Steps to reproduce
- Run Drupal under Apache
- Set up an image style and use the "Convert" action to convert the source image (e.g. jpg) to webp (as of #2340699: Let GDToolkit support WEBP image format), which was a great addition to Drupal 9.2 to allow webp generation by core: https://www.drupal.org/node/3171135
- Get the image and have a look at the returned type header. It's not image/webp as expected , but still the old format.
I'm using Firefox on Windows.
Chrome is even crazier and returns type "document" for the webp image.
Google Page speed also complains
Serve images in modern formats
but shows the .webp files as an example for files to be optimized. This is also unexpected, and I guess due to the wrong headers returned.
Proposed resolution
Return the correct MIME type for the converted image.
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
A directive has been added to core's default .htaccess
file that attaches the correct image/webp
header for webp images when the MIME Apache module is enabled. This is needed for sites hosted on Apache web servers running on operating systems that do not support the webp image MIME type. Sites should update their .htaccess
files to take advantage of this improvement.