influxdata / influxdata/docs-v2
perf: Defer third-party scripts (Kapa AI widget, reCAPTCHA) until interaction
- Dominant language
- JavaScript
- Stars
- 82
- Forks
- 326
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 82
Description
## Problem
A Lighthouse 13.2.0 audit of https://docs.influxdata.com/influxdb3/enterprise/ (2026-07-20, mobile emulation: Moto G Power 2022, simulated throttling 150 ms RTT / 1.6 Mbps / 4x CPU slowdown) scored **Performance 47**. The dominant cost is third-party JavaScript that loads eagerly on every page view even though most visitors never use it.
**Metrics affected**
| Metric | Value | Score |
| --- | --- | --- |
| Total Blocking Time | 860 ms | 0.33 |
| Time to Interactive | 21.1 s | 0.01 |
| Max Potential FID | 730 ms | 0.01 |
| Total byte weight | 4,106 KiB (3,035 KiB scripts) | — |
## Lighthouse findings
**Kapa AI widget** (`https://widget.kapa.ai/kapa-widget.bundle.js`):
- 2,065,909 bytes transferred — half the total page weight
- 654,717 bytes (~32%) unused (`unused-javascript` audit)
- Longest main-thread task on the page: **725 ms** (`long-tasks` audit)
- 770 ms total CPU time (`bootup-time` audit)
- Cache TTL is only 10 minutes, so repeat visits re-download ~1.85 MB (`cache-insight` audit)
**Kapa metrics loader** (`https://metrics.kapa.ai/web/v3/.../loader_v3.12.0.js`):
- 67,793 bytes; long tasks of 183 ms and 110 ms; 498 ms total CPU time
**reCAPTCHA Enterprise** (`https://www.gstatic.com/recaptcha/releases/.../recaptcha__en.js`):
- 382,517 bytes, fetched **three times** (main frame, anchor iframe, web worker) = ~1,147 KiB total transfer
- 427,857 bytes (~48%) unused
- 443 ms total CPU time
## Proposed fix
- Lazy-load the Kapa widget bundle on first interaction (click on the Ask AI trigger, an `ask-ai-open` element, or the search shortcut), showing a lightweight facade until then. Entry points: `assets/js/ask-ai.ts`, `assets/js/ask-ai-trigger.js`, `layouts/partials/footer/widgets/ask-ai-trigger.html`.
- Defer reCAPTCHA loading until the user interacts with the feedback form (`layouts/partials/article/feedback.html`) instead of loading it on every page view.
## Reproduce
Run Lighthouse (navigation mode, mobile, default throttling) against https://docs.influxdata.com/influxdb3/enterprise/ and inspect the `third-parties-insight`, `long-tasks`, `bootup-time`, and `unused-javascript` audits.
Related: accessibility/SEO fixes from the same audit are on branch `claude/influxdb-docs-lighthouse-chphcn`.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by running Lighthouse in navigation mode against the InfluxDB 3 Enterprise page and inspect the third-parties-insight, long-tasks, bootup-time, and unused-javascript audits. Read assets/js/ask-ai.ts, assets/js/ask-ai-trigger.js, layouts/partials/footer/widgets/ask-ai-trigger.html, and layouts/partials/article/feedback.html. Done means Kapa and reCAPTCHA load only after their described interactions while the relevant audits show reduced eager third-party work.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- frontend, performance
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100