Skip to content

Switch initial viewport embeds from preconnect to dns-prefetch links#2256

Merged
westonruter merged 15 commits intoWordPress:trunkfrom
dhruvang21:patch-1
Feb 27, 2026
Merged

Switch initial viewport embeds from preconnect to dns-prefetch links#2256
westonruter merged 15 commits intoWordPress:trunkfrom
dhruvang21:patch-1

Conversation

@dhruvang21
Copy link
Contributor

@dhruvang21 dhruvang21 commented Nov 4, 2025

Summary

Fixes #2247

Relevant technical choices

  • Add dns-prefetch support for OD_Link_Collection::add_link()
  • Replace rel=preconnect with rel=dns-prefetch for embed resources.

@github-actions
Copy link

github-actions bot commented Nov 4, 2025

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 props-bot label.

Unlinked Accounts

The following contributors have not linked their GitHub and WordPress.org accounts: @hrishikesh2810.

Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Unlinked contributors: hrishikesh2810.

Co-authored-by: dhruvang21 <dhruvang21@git.wordpress.org>
Co-authored-by: westonruter <westonruter@git.wordpress.org>
Co-authored-by: peterwilsoncc <peterwilsoncc@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Copy link
Member

@westonruter westonruter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR.

I left some feedback.

Note that for the unit test failures, you'll need to update the snapshots. You can do this by first running all the unit tests locally, for example via npm run test-php and then update the snapshots via npm run update-test-case-snapshots. At this point, you should be able to do npm run test-php again, and the tests should pass. You can then commit all the HTML file updates.

@dhruvang21
Copy link
Contributor Author

@westonruter i did run command npm run test-php but it throws this error

RequestError
    at ClientRequest.<anonymous> (/var/www/wp-performance/wp-content/performance/node_modules/got/dist/source/core/index.js:970:111)
    at Object.onceWrapper (node:events:635:26)
    at ClientRequest.emit (node:events:532:35)
    at origin.emit (/var/www/wp-performance/wp-content/performance/node_modules/@szmarczak/http-timer/dist/source/index.js:43:20)
    at emitErrorEvent (node:_http_client:103:11)
    at TLSSocket.socketErrorListener (node:_http_client:506:5)
    at TLSSocket.emit (node:events:520:28)
    at emitErrorNT (node:internal/streams/destroy:170:8)
    at emitErrorCloseNT (node:internal/streams/destroy:129:3)
    at process.processTicksAndRejections (node:internal/process/task_queues:90:21)AggregateError [ETIMEDOUT]: 
    at internalConnectMultiple (node:net:1117:18)
    at internalConnectMultiple (node:net:1185:5)
    at Timeout.internalConnectMultipleTimeout (node:net:1711:5)
    at listOnTimeout (node:internal/timers:596:11)
    at process.processTimers (node:internal/timers:529:7) {
  code: 'ETIMEDOUT',
  timings: {
    start: 1762327934784,
    socket: 1762327934784,
    lookup: 1762327934809,
    connect: undefined,
    secureConnect: undefined,
    upload: undefined,
    response: undefined,
    end: undefined,
    error: 1762327935060,
    abort: undefined,
    phases: {
      wait: 0,
      dns: 25,
      tcp: undefined,
      tls: undefined,
      request: undefined,
      firstByte: undefined,
      download: undefined,
      total: 276
    }
  }
}

@westonruter
Copy link
Member

i did run command npm run test-php but it throws this error

@dhruvang21 Did you follow the setup steps on the handbook page?

@dhruvang21
Copy link
Contributor Author

@westonruter yes

@westonruter
Copy link
Member

OK, I'm not sure why it's not working for you. I've updated the snapshots in 16fa2b8

@codecov
Copy link

codecov bot commented Nov 7, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 69.33%. Comparing base (695d5b8) to head (ee466f5).
⚠️ Report is 16 commits behind head on trunk.

Additional details and impacted files
@@            Coverage Diff             @@
##            trunk    #2256      +/-   ##
==========================================
+ Coverage   69.32%   69.33%   +0.01%     
==========================================
  Files          90       90              
  Lines        7746     7749       +3     
==========================================
+ Hits         5370     5373       +3     
  Misses       2376     2376              
Flag Coverage Δ
multisite 69.33% <100.00%> (+0.01%) ⬆️
single 35.73% <30.00%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@westonruter westonruter added this to the embed-optimizer n.e.x.t milestone Nov 7, 2025
@westonruter westonruter added [Type] Bug An existing feature is broken [Plugin] Embed Optimizer Issues for the Embed Optimizer plugin (formerly Auto Sizes) labels Nov 7, 2025
@westonruter
Copy link
Member

Based on @peterwilsoncc's comment, it seems I was overly aggressive in the switch to dns-prefeth. There would still be value to have some preconnect links, when they are used directly on the page and not exclusively in an iframe.

@dhruvang21
Copy link
Contributor Author

@westonruter how should we move further here?

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates Embed Optimizer’s resource-hint generation to avoid wasted cross-origin preconnect usage by switching affected hints to dns-prefetch, and refreshes related test fixtures across plugins.

Changes:

  • Switch Embed Optimizer’s generated resource hints from preconnect to dns-prefetch for embed-related hosts.
  • Extend Optimization Detective’s link-attribute PHPStan type to include dns-prefetch.
  • Update Image Prioritizer and Embed Optimizer expected HTML fixtures to match updated output.

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
plugins/optimization-detective/class-od-link-collection.php Extends LinkAttributes rel type to include dns-prefetch.
plugins/embed-optimizer/class-embed-optimizer-tag-visitor.php Replaces preconnect-link injection with dns-prefetch-link injection for embeds.
plugins/image-prioritizer/tests/test-cases/video-without-poster-lcp-element-on-desktop-only/expected.html Updates expected script-tag attribute ordering in fixture output.
plugins/image-prioritizer/tests/test-cases/video-with-poster-lcp-element-on-mobile-and-desktop-but-not-tablet/expected.html Updates expected script-tag attribute ordering in fixture output.
plugins/image-prioritizer/tests/test-cases/video-with-poster-lcp-element-on-desktop-only/expected.html Updates expected script-tag attribute ordering in fixture output.
plugins/image-prioritizer/tests/test-cases/video-with-poster-lcp-element-on-all-breakpoints/expected.html Updates expected script-tag attribute ordering in fixture output.
plugins/image-prioritizer/tests/test-cases/video-with-large-poster-and-desktop-url-metrics-missing/expected.html Updates expected script-tag attribute ordering in fixture output.
plugins/image-prioritizer/tests/test-cases/video-with-large-poster-and-desktop-url-metrics-collected/expected.html Updates expected script-tag attribute ordering in fixture output.
plugins/image-prioritizer/tests/test-cases/url-metric-only-captured-for-one-breakpoint/expected.html Updates expected script-tag attribute ordering in fixture output.
plugins/image-prioritizer/tests/test-cases/preload-links-with-one-half-stale-group/expected.html Updates expected script-tag attribute ordering in fixture output.
plugins/image-prioritizer/tests/test-cases/picture-element-as-lcp-tablet-and-desktop-metrics-missing/expected.html Updates expected script-tag attribute ordering in fixture output.
plugins/image-prioritizer/tests/test-cases/only-mobile-and-desktop-groups-are-populated/expected.html Updates expected script-tag attribute ordering in fixture output.
plugins/image-prioritizer/tests/test-cases/no-url-metrics/expected.html Updates expected script-tag attribute ordering in fixture output.
plugins/image-prioritizer/tests/test-cases/no-url-metrics-with-non-background-image-style/expected.html Updates expected script-tag attribute ordering in fixture output.
plugins/image-prioritizer/tests/test-cases/no-url-metrics-with-data-url-image/expected.html Updates expected script-tag attribute ordering in fixture output.
plugins/image-prioritizer/tests/test-cases/no-url-metrics-with-data-url-background-image/expected.html Updates expected script-tag attribute ordering in fixture output.
plugins/image-prioritizer/tests/test-cases/no-url-metrics-for-image-without-src/expected.html Updates expected script-tag attribute ordering in fixture output.
plugins/image-prioritizer/tests/test-cases/no-url-metrics-but-server-side-heuristics-added-fetchpriority-high/expected.html Updates expected script-tag attribute ordering in fixture output.
plugins/image-prioritizer/tests/test-cases/multiple-videos-with-desktop-metrics-missing/expected.html Updates expected script-tag attribute ordering in fixture output.
plugins/image-prioritizer/tests/test-cases/multiple-videos-on-all-breakpoints/expected.html Updates expected script-tag attribute ordering in fixture output.
plugins/image-prioritizer/tests/test-cases/lcp-element-external-background-image-present-in-document-and-partially-populated-samples/expected.html Updates expected script-tag attribute ordering in fixture output.
plugins/image-prioritizer/tests/test-cases/img-non-native-lazy-loading/expected.html Updates expected script-tag attribute ordering in fixture output.
plugins/image-prioritizer/tests/test-cases/fetch-priority-high-on-lcp-image-common-on-mobile-and-desktop-with-url-metrics-missing-in-other-groups/expected.html Updates expected script-tag attribute ordering in fixture output.
plugins/image-prioritizer/tests/test-cases/different-lcp-elements-for-two-non-consecutive-breakpoints/expected.html Updates expected script-tag attribute ordering in fixture output.
plugins/image-prioritizer/tests/test-cases/different-lcp-elements-for-two-non-consecutive-breakpoints-and-one-is-stale/expected.html Updates expected script-tag attribute ordering in fixture output.
plugins/image-prioritizer/tests/test-cases/different-lcp-elements-for-non-consecutive-viewport-groups-with-missing-data-for-middle-group/expected.html Updates expected script-tag attribute ordering in fixture output.
plugins/image-prioritizer/tests/test-cases/different-lcp-elements-for-all-breakpoints/expected.html Updates expected script-tag attribute ordering in fixture output.
plugins/image-prioritizer/tests/test-cases/common-lcp-image-with-old-xpath-format/expected.html Updates expected script-tag attribute ordering in fixture output.
plugins/image-prioritizer/tests/test-cases/common-lcp-image-with-fully-incomplete-sample-data/expected.html Updates expected script-tag attribute ordering in fixture output.
plugins/image-prioritizer/tests/test-cases/background-image-outside-viewport-with-desktop-metrics-missing/expected.html Updates expected script-tag attribute ordering in fixture output.
plugins/embed-optimizer/tests/test-cases/single-youtube-embed-outside-viewport-on-mobile/expected.html Updates expected resource-hint links from preconnect to dns-prefetch.
plugins/embed-optimizer/tests/test-cases/single-youtube-embed-inside-viewport/expected.html Updates expected resource-hint links from preconnect to dns-prefetch.
plugins/embed-optimizer/tests/test-cases/single-youtube-embed-inside-viewport-with-only-mobile-url-metrics/expected.html Updates expected resource-hint links from preconnect to dns-prefetch.
plugins/embed-optimizer/tests/test-cases/single-wordpress-tv-embed-outside-viewport-on-mobile/expected.html Updates expected resource-hint links from preconnect to dns-prefetch.
plugins/embed-optimizer/tests/test-cases/single-wordpress-tv-embed-inside-viewport/expected.html Updates expected resource-hint links from preconnect to dns-prefetch.
plugins/embed-optimizer/tests/test-cases/single-twitter-embed-outside-viewport-on-mobile/expected.html Updates expected resource-hint links from preconnect to dns-prefetch.
plugins/embed-optimizer/tests/test-cases/single-twitter-embed-inside-viewport/expected.html Updates expected resource-hint links from preconnect to dns-prefetch.
plugins/embed-optimizer/tests/test-cases/single-twitter-embed-inside-viewport-without-resized-data/expected.html Updates expected resource-hint links from preconnect to dns-prefetch.
plugins/embed-optimizer/tests/test-cases/single-twitter-embed-inside-viewport-one-group/expected.html Updates expected resource-hint links from preconnect to dns-prefetch.
plugins/embed-optimizer/tests/test-cases/figures-with-fancy-ids/expected.html Updates expected resource-hint links from preconnect to dns-prefetch.
plugins/embed-optimizer/tests/test-cases/all-embeds-inside-viewport/expected.html Updates expected resource-hint links from preconnect to dns-prefetch.
Comments suppressed due to low confidence (1)

plugins/embed-optimizer/class-embed-optimizer-tag-visitor.php:284

  • Typo in the docblock: "dns-prefech" should be "dns-prefetch".
	 * Gets dns-prefech URLs based on embed type.
	 *

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@westonruter westonruter added the [Plugin] Optimization Detective Issues for the Optimization Detective plugin label Feb 27, 2026
westonruter and others added 3 commits February 26, 2026 16:49
…gin embeds

- Update Embed_Optimizer_Tag_Visitor to use dns-prefetch instead of preconnect.
- Add support and validation for dns-prefetch in OD_Link_Collection.
- Update plugin headers, readme.txt, and documentation for consistency.

Co-authored-by: gemini-cli <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Copy link
Member

@westonruter westonruter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delay in reviewing this!

@westonruter westonruter changed the title Embed Optimizer: Switch cross-origin embeds from preconnect to dns-pr… Embed Optimizer: Switch cross-origin embeds from preconnect to dns-prefetch Feb 27, 2026
@westonruter westonruter changed the title Embed Optimizer: Switch cross-origin embeds from preconnect to dns-prefetch Switch initial viewport embeds from preconnect to dns-prefetch Feb 27, 2026
@westonruter westonruter changed the title Switch initial viewport embeds from preconnect to dns-prefetch Switch initial viewport embeds from preconnect to dns-prefetch links Feb 27, 2026
@westonruter westonruter merged commit ee918b1 into WordPress:trunk Feb 27, 2026
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Plugin] Embed Optimizer Issues for the Embed Optimizer plugin (formerly Auto Sizes) [Plugin] Optimization Detective Issues for the Optimization Detective plugin [Type] Bug An existing feature is broken

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Embed Optimizer wastefully adds preconnect links for initial-viewport embeds when only dns-prefetch is used

3 participants