Skip to content

Lazy load CWV distribution histogram on user click - #1328

Open
max-ostapenko wants to merge 2 commits into
migrate-astro-appenginefrom
courageous-galliform
Open

max-ostapenko wants to merge 2 commits into
migrate-astro-appenginefrom
courageous-galliform

Conversation

@max-ostapenko

Copy link
Copy Markdown
Contributor

Summary

The /v1/cwv-distribution endpoint queries BigQuery directly on the backend and is costly to execute on every page load. Because the histogram chart in the tech report is collapsed by default, this PR optimizes data loading to only fetch when requested by the user.

Changes

  • Lazy load on button click:
    • Prevent initial fetch of CWV distribution data on page load.
    • Fetch distribution data only when the user expands the section via the "Show histogram" button (#cwv-distribution-btn).
    • Cache fetched data so subsequent collapse/expand toggles do not re-fetch.
  • Maintain filter update synchronization:
    • When the histogram is open and the user clicks the "Update" button (#submit-form), append #section-cwv_distribution to the URL so the section remains open after reload.
    • Automatically fetch fresh distribution data matching the newly applied filters upon reload.
    • If the histogram is collapsed, filter updates do not trigger any distribution fetch.
  • Race condition guards:
    • Added isLoading state and URL tracking (getUrl()) to prevent duplicate in-flight requests between date updates and toggle events.

Verification

Verified in browser via dev server (http://localhost:8080/reports/techreport/tech?tech=WordPress):

  1. Initial page load: 0 requests to /v1/cwv-distribution.
  2. Expand click: Exactly 1 request sent, chart rendered with Core Web Vitals threshold zones.
  3. Collapse & re-open: Reused cached data, 0 additional requests.
  4. Filter update while visible: Preserved section state and reloaded data for updated filter parameters.
  5. Filter update while hidden: Remained hidden with 0 requests sent.

@max-ostapenko
max-ostapenko added this pull request to stack #1329 September 13, 2026 07:14
Comment thread src/js/techreport/cwvDistribution.js Outdated
@max-ostapenko
max-ostapenko force-pushed the courageous-galliform branch 4 times, most recently from a230c9d to 18f0bff Compare September 14, 2026 18:35
Signed-off-by: Max Ostapenko <1611259+max-ostapenko@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants