Opened 2 years ago
Last modified 2 years ago
#56529 new enhancement
Add minimal JPEG fallback script to address limited lack of WebP support
Reported by: | flixos90 | Owned by: | |
---|---|---|---|
Milestone: | Future Release | Priority: | normal |
Severity: | normal | Version: | |
Component: | Media | Keywords: | has-patch has-unit-tests |
Focuses: | Cc: |
Description
As noted in the original ticket #55443, there is still a very small global percentage of browser usage (between 1% and 3%) where the browser does not support WebP. Most of that is comprised of Safari on certain outdated versions of Mac OS and iOS.
A pull request for this has been already in the works for the previously envisioned multi MIME type infrastructure (see e.g. https://core.trac.wordpress.org/ticket/55443#comment:115), and while this infrastructure has been reverted, most of the code for the fallback script is still relevant, so the PR can probably be continued and only has to be adjusted to the new circumstances where every image size has either WebP or JPEG available.
The new approach here for the fallback needs to be as follows (when WebP is not supported): Choose the smallest available version of the image that has at least as large dimensions as the WebP version and has the same aspect ratio.
Change History (3)
This ticket was mentioned in PR #3034 on WordPress/wordpress-develop by mukeshpanchal27.
2 years ago
#1
- Keywords has-patch has-unit-tests added
felixarntz commented on PR #3034:
2 years ago
#2
@mukeshpanchal27 This is now ready to proceed, however it has to be updated to the new approach where only WebP or JPEG is available per image size. No sources
data is present anymore, so this needs to be fully dependent on the single image that is available for each size. I've opened a new Trac ticket specifically for this functionality: https://core.trac.wordpress.org/ticket/56529
I believe most of the code in this PR can remain unchanged. The two main things that need to be updated are:
- The
wp_image_use_alternate_mime_types()
function no longer exists. So we need to handle setting the global$_wp_image_mime_fallback_should_load
in a different way. Since we now no longer do frontend replacements of JPEG at all, I suggest we instead incorporate this somewhere intowp_filter_content_tags()
or potentially a new helper function where we check whether the content includes any.webp
image, and if so set the global so that the minimal fallback script is included. - The actual JS code in the
wp-image-mime-fallback.js
script needs to be changed according to the new conditions. We will now have to replace every WebP version with the best available JPEG version, which is- the smallest available JPEG with at least the dimensions of the WebP
- using the same aspect ratio
cc @adamsilverstein
The PR adds fallback JPEG images in the frontend when WebP is not supported by the browser.
Trac ticket: https://core.trac.wordpress.org/ticket/56529
### BrowserStack testing results for different browsers and devices.
Random browsers and devices: https://www.browserstack.com/screenshots/a35c8ac34c18df3c07744012bb8e7957dfa6823d
Mac OS & Windows & Android devices: https://www.browserstack.com/screenshots/a3c0369dd8a37a3bc278b3478ba6780500e55aaa
iOS iPhone and iPad devices: https://www.browserstack.com/screenshots/3536f52ca1a237d26f48028f84fc13c2a59a6212