Skip to content

Enhance JS replacement mechanism for WebP to JPEG to more reliably replace full file name #426

@felixarntz

Description

@felixarntz

Follow-up to #341: The implementation from that PR #360 which should replace WebP file URLs with their corresponding JPEG file URLs is currently a bit simplified, replacing purely the .webp extension with the corresponding image/jpeg file's extension.

While this (correctly) does take the JPEG extension into account (which could be jpeg, jpg, or jpe), there are potentially other quirks with file names that may not always match. #358 has ensured that a WebP file generated would never be for another JPEG file and thus would never have a different name by default, which makes this a non-urgent issue, but still the current implementation is not quite reliable and error-prone, should the behavior of additional MIME type generation change in the future.

A potential approach to fix this would be to change the JS implementation as follows:

  • Instead of just replacing all .webp extensions with the corresponding image/jpeg file's extension, the replacement should happen individually for the full/original image size as well as for all sub-sizes.
  • For every size, the full file URL to the image/webp version should be replaced with the full file URL to the image/jpeg version, or at least the full file name should be replaced instead of only the extension.
  • The most important here though is to do it per size individually since there may be slight differences between the files for those as well. We shouldn't only rely on the full image to determine how to replace all URLs.

This originally was raised in #360 (comment). cc @peterwilsoncc

Metadata

Metadata

Labels

[Plugin] Modern Image FormatsIssues for the Modern Image Formats plugin (formerly WebP Uploads)[Type] EnhancementA suggestion for improvement of an existing feature

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions