Bug Description
When using AVIF images as background images, the validation process in the image prioritizer plugin fails because the server returns an incorrect MIME type. Specifically, a HEAD request to an AVIF image URL (e.g., demo-img-scaled-jpg.avif) is returning application/octet-stream rather than the expected image/avif (or any MIME type starting with image/). This leads the function image_prioritizer_validate_background_image_url to reject the background image, triggering a PHP notice and preventing the image from being included in URL metrics collection.
Many web servers, including default configurations for popular servers like Nginx or Apache, may not be set up to serve AVIF images with the proper MIME type header. As a result, even valid AVIF background images are flagged as invalid.
Below is the error logged:
[21-Mar-2025 17:46:20 UTC] PHP Notice: image_prioritizer_filter_rest_request_before_callbacks(): Error: HEAD request for background image URL did not return an image Content-Type: application/octet-stream. Background image URL: https://core-performance.local/wp-content/uploads/2025/03/demo-img-scaled-jpg.avif. in /Users/aditya/Local Sites/core-performance/app/public/wp-includes/functions.php on line 6114
We do have a site health check specifically for missing AVIF headers so I am not sure if we should handle this case.
Bug Description
When using AVIF images as background images, the validation process in the image prioritizer plugin fails because the server returns an incorrect MIME type. Specifically, a HEAD request to an AVIF image URL (e.g.,
demo-img-scaled-jpg.avif) is returningapplication/octet-streamrather than the expectedimage/avif(or any MIME type starting withimage/). This leads the functionimage_prioritizer_validate_background_image_urlto reject the background image, triggering a PHP notice and preventing the image from being included in URL metrics collection.Many web servers, including default configurations for popular servers like Nginx or Apache, may not be set up to serve AVIF images with the proper MIME type header. As a result, even valid AVIF background images are flagged as invalid.
Below is the error logged:
We do have a site health check specifically for missing AVIF headers so I am not sure if we should handle this case.