Don't create derivative image if the derivative already exists

Created on 22 December 2023, 12 months ago

Problem/Motivation

Trying to load https://site.com/sites/default/files/styles/thumbnail/public/image/645e0... will re-execute the generating code for the WebP format even if the derivate image already exists.

The image style URL is normally cached by the brower so i can understand that's not a big deal, but it's not necessary to re-execute if already exists.

I've also had an issue with existing source files having the same pattern of jpg.webp or png.webp etc.. . It will consider the requested file as the WebP module strategy works, the requested file extension with .web have an existing source file without the.webp.

Steps to reproduce

Create an media with xxxx.jpeg.webp (as source file) and try load derivate image with an image style, the image will be broken.

Proposed resolution

Process the $image_uri to drop the .webp extension only if the file does not exists.

if (!file_exists($image_uri) && ($webp_wanted = preg_match('/\.webp$/', $image_uri))) {
  // Drop the webp extension.
  $image_uri = $this->webp->getWebpDestination($image_uri, '@directory@filename');
}
🐛 Bug report
Status

Needs review

Version

1.0

Component

Code

Created by

🇫🇷France xavier.masson Haute-Normandie

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024