Skip to content
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

Other optimization plugins may delay the loading of Optimization Detective's detect.js and thus break detection #1890

Open
westonruter opened this issue Feb 26, 2025 · 1 comment
Labels
[Plugin] Optimization Detective Issues for the Optimization Detective plugin [Type] Bug An existing feature is broken

Comments

@westonruter
Copy link
Member

When I analyzed sites on HTTP Archive which ran Optimization Detective, I encountered some sites that lacked any URL Metrics being collected. When looking further, I found that they were running WP Rocket and that WP Rocket was attempting to lazy-load the detect.js script:

<script type="rocketlazyloadscript" data-rocket-type="module">
import detect from "https:\/\/example.com\/wp-content\/plugins\/optimization-detective\/detect.js?ver=0.4.1"; detect( {"serveTime":1740596242213.1091,"detectionTimeWindow":5000,"isDebug":false,"restApiEndpoint":"https:\/\/example.co\/wp-json\/optimization-detective\/v1\/url-metrics:store","restApiNonce":"2f888614b1","currentUrl":"https:\/\/example.co\/","urlMetricsSlug":"f087b88472f15a472c3b99c50a992bd9","urlMetricsNonce":"5abb04aa0a","urlMetricsGroupStatuses":[{"minimumViewportWidth":0,"complete":false},{"minimumViewportWidth":481,"complete":false},{"minimumViewportWidth":601,"complete":false},{"minimumViewportWidth":783,"complete":false}],"storageLockTTL":60,"webVitalsLibrarySrc":"https:\/\/example.co\/wp-content\/plugins\/optimization-detective\/build\/web-vitals.js?ver=4.2.1"} );
</script>

This breaks the detection logic because (1) the detect.js module script is printed in the footer so it will only be loaded when the user scrolls down to the bottom of the page, and (2) detection aborts if it the user is not at the top of the page (since we need to measure what is in the initial viewport).

Therefore, I'm opening this task to reach out to WP Rocket to exclude Optimization Detective's detect.js script by default. When at WordCamp Asia I also talked with someone who uses PerfMatters to similarly delay loading scripts, so we should check if they have any default patterns for excluding as well.

@westonruter westonruter added [Plugin] Optimization Detective Issues for the Optimization Detective plugin [Type] Bug An existing feature is broken labels Feb 26, 2025
@github-project-automation github-project-automation bot moved this to Not Started/Backlog 📆 in WP Performance 2025 Feb 26, 2025
@westonruter westonruter moved this from Not Started/Backlog 📆 to To Do 🔧 in WP Performance 2025 Feb 27, 2025
@westonruter
Copy link
Member Author

Documentation for WP Rocket: Delay JavaScript execution. See also Delay JavaScript Execution compatibility exclusions.

Documentation for Perfmatters: How to delay JavaScript until user interaction in WordPress. See in particular the Common JS delay exclusions.

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
Status: To Do 🔧
Development

No branches or pull requests

1 participant