Skip to content

Fix WebP module: Safari srcset 404s, missing srcset, mixed content - #89

Open
RichKenyon wants to merge 1 commit into
WebDevStudios:mainfrom
RichKenyon:fix/webp-safari-srcset
Open

RichKenyon wants to merge 1 commit into
WebDevStudios:mainfrom
RichKenyon:fix/webp-safari-srcset

Conversation

@RichKenyon

@RichKenyon RichKenyon commented Oct 7, 2026 •

Copy link
Copy Markdown

Fixes #88

What this changes

inc/performance/webp-uploads.php

  • browser_supports_webp() returns apply_filters( 'wdsbt_serve_webp', true ) instead of sniffing the navigation Accept header. Safari doesn't send image/webp there, and one URL served different HTML per browser.
  • Removed the client-side replaceImagesWithWebP() script, which was printed three times. Its srcset rewrite dropped every candidate's file extension, which caused the Safari 404s in the issue.
  • Unhooked replace_attachment_image_src_with_webp() from wp_get_attachment_image_src. Swapping the src before core builds the srcset left core unable to match a size, so no image had a srcset. The src is now swapped in add_webp_source(), and each candidate in replace_srcset_with_webp(), after core has built them.
  • New webp_sibling_url() helper: the content and output-buffer passes now swap only to a .webp that exists.
  • New webp_upload_dir() helper: URLs built from wp_upload_dir(), and stored WebP URLs, follow the request's scheme, so an https page never gets http:// images.

inc/performance/dominant-color-images.php

  • The fade-in script is attached to wdsbt-scripts. wp-block-library is a stylesheet handle, so the script never printed and lazy images stayed at opacity: 0.8. The script now also checks readyState, since a deferred handle can run after DOMContentLoaded.

Testing

  • PHPCS: composer run-script phpcs passes with no errors or warnings, the same as main. No JS or CSS files changed.
  • Client theme: the same patch is running on a client theme built from wds-bt, on staging. Over its 69 pages, with Safari 26.6 and Chrome 154 request headers:
    • the image markup is identical in both browsers;
    • all 138 upload URLs return 200;
    • no src or srcset URL lacks an extension;
    • 466 <img> tags carry a srcset again (none did before in Chrome).
  • Safari: before the patch, Safari 26.6's console showed the 404s for extension-less srcset URLs. With its request headers, every candidate now resolves to an existing .webp.
  • Dominant color: in Chrome, every lazy .has-dominant-color image reaches opacity: 1 after it loads.
  • Not tested: Firefox in-browser (only its Accept header was checked); Windows browsers.
  • Accessibility: no markup or UI changes beyond the image URLs.

- Serve WebP to every browser (filter `wdsbt_serve_webp`, default true)
  instead of sniffing the navigation Accept header, which Safari leaves
  without image/webp. One URL now serves one page.
- Remove the client-side replaceImagesWithWebP() script (printed three
  times). Its srcset rewrite dropped each candidate's file extension,
  so browsers that picked a srcset candidate requested
  ".../image-768x511 768w" and got a 404.
- Stop swapping the src in wp_get_attachment_image_src: core could not
  match a .webp src to a registered size, so no image got a srcset.
  The src is swapped in add_webp_source() and each candidate in
  replace_srcset_with_webp(), after core has built them.
- Content and output-buffer passes swap only to a .webp that exists
  (webp_sibling_url()).
- Built and stored URLs follow the request's scheme (set_url_scheme),
  so an https page never gets http:// images.
- dominant-color-images.php: attach the fade-in script to
  `wdsbt-scripts`; `wp-block-library` is a stylesheet handle, so the
  script never printed and lazy images stayed at opacity 0.8.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012aj8kRbJi5ivGR4soA2g4B
@RichKenyon
RichKenyon requested a review from khleomix as a code owner October 7, 2026 14:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WebP module: Safari 404s on srcset images, and no image gets a srcset

1 participant