Skip to content

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

@westonruter

Description

@westonruter

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    Status

    To Do 🔧

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions