From 141556567f8f22d319f674641856f7a5b09db71f Mon Sep 17 00:00:00 2001 From: Pedro Paulo Vezza Campos Date: Fri, 29 May 2026 08:43:41 -0700 Subject: [PATCH] Defer client telemetry off the load critical path The App Insights /v2.1/track POST was firing during page load, and its slow westus2 ingestion round-trip dominated the critical request chain (~2,172 ms max critical path latency). Telemetry is pure analytics, so it has no business on the load path. Lazy-import the telemetry chunk (web-vitals + AI client) and fire the first pageview only on requestIdleCallback, with a load-event fallback. This splits the eager Layout script from 14.7 KB to 1.7 KB and turns the telemetry bundle into a dynamic-import chunk that isn't fetched until the main thread is idle. web-vitals reads buffered LCP/FCP/CLS entries, so deferring observer registration loses no metrics. Co-Authored-By: Claude Opus 4.8 (1M context) --- src/layouts/Layout.astro | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/layouts/Layout.astro b/src/layouts/Layout.astro index cae8917..12bddfa 100644 --- a/src/layouts/Layout.astro +++ b/src/layouts/Layout.astro @@ -111,9 +111,21 @@ const telemetryConfig = Astro.locals.telemetry?.clientConfig() ?? null;