Exclude imagesrcset links from Link response header#2578
Conversation
Responsive image preloads (imagesrcset/imagesizes) can make the Link response header exceed reverse-proxy header size limits, causing intermittent 502s. These links already get an HTML <link rel=preload> tag unconditionally, so exclude them from the Link header and rely on the HTML tag instead. Refs WordPress#2304
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## trunk #2578 +/- ##
==========================================
- Coverage 70.35% 70.31% -0.05%
==========================================
Files 91 91
Lines 7867 7858 -9
==========================================
- Hits 5535 5525 -10
- Misses 2332 2333 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
@westonruter Closing #2572 as a duplicate of this PR. This one fully excludes Ready for review when you have a moment. |
Summary
Fixes #2304
Relevant technical choices
OD_Link_Collection::get_response_header()now excludes any link withimagesrcsetset (responsive image preloads) from theLink:HTTP response header. These links already get an HTML<link rel="preload" imagesrcset="..." ...>tag unconditionally viaget_html(), so no functionality is lost — the responsive preload just moves to HTML-only delivery.href, e.g. video posters, background images) are unaffected and still go into both the header and the HTML.$context->link_collection->add_link()with attributes; the header/HTML emission choice is made entirely in this one method in Optimization Detective.srcsetvariants can push the combined response header size past common reverse-proxy limits (Nginx/Apache default buffers), causing intermittent 502 Bad Gateway errors — worse for logged-in users where cookies add to the header total.<link rel="preload">elements rather thanLink:response headers.<link>tags to right after<meta charset>/<title>in<head>) is left as a possible follow-up, not included here.How to test
srcset/sizes, ideally long/non-ASCII filename) detected as the LCP element.Link: ...imagesrcset=...entry.<link rel="preload" imagesrcset="..." ...>tag is still present in<head>and the image still loads with priority.Testing already done
npm run phpstan— cleancomposer lint:optimization-detective(phpcs) — cleancoderabbit review --agent— 0 findings on changed filestest-class-od-link-collection.phpcovering the excluded-from-header behaviorUse of AI Tools
Confirmed I've used Claude AI to generate this PR. Claude Code was used for the full workflow: investigating the issue and root cause across
optimization-detectiveandimage-prioritizer, drafting and implementing the fix, updating tests, and running lint/static analysis. I reviewed the diff, the reasoning, and the test changes, and take responsibility for the change as submitted.