Skip to content

Delay loading detect module until page is loaded and idle #2017

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: trunk
Choose a base branch
from

Conversation

westonruter
Copy link
Member

@westonruter westonruter commented May 26, 2025

The detect module is loaded via a dynamic import which involves a high fetch priority. No resources for Optimization Detective should ever compete with the loading of any resources for the critical rendering path. So this introduces an inlined detect-loader script module which explicitly waits for the page to be fully loaded and idle before beginning to load the detect module. This wait-until-idle logic was previously in the detect module itself, but it is better to put in inline on the page to delay the loading of the script module.

On a single post template with the LCP element being the featured image, the impact on the LCP-TTFB metric are as follows (capturing the median of 50 requests):

Network Conditions Before After Diff (ms) Diff (%)
Fast 4G 771.75 766.7 -5.05 -0.65%
broadband 252.85 243.95 -8.90 -3.52%

Network Waterfall

Before

image

After

image

@westonruter westonruter added [Type] Bug An existing feature is broken [Plugin] Optimization Detective Issues for the Optimization Detective plugin labels May 26, 2025
@westonruter
Copy link
Member Author

  • Update tests to account for the inlined JS.

Related:

The Optimization Detective client-side extension modules are being loaded sequentially:

image

We should look at loading them in parallel.

@westonruter westonruter self-assigned this May 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[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.

1 participant