Skip to content

perf: defer narrations, analytics, and header toggles until after load - #223

Merged
adeonir merged 16 commits into
mainfrom
adk-307-load-performance-defer-narrations-analytics-and-header-toggles
Nov 14, 2026
Merged

adeonir merged 16 commits into
mainfrom
adk-307-load-performance-defer-narrations-analytics-and-header-toggles

Conversation

@adeonir

@adeonir adeonir commented Nov 14, 2026

Copy link
Copy Markdown
Owner

Summary

The home no longer downloads narrations, analytics, or the header toggles' React runtime during the first render, and the global stylesheet ships inside the HTML.

flowchart LR
  A[HTML + inline CSS] --> B[load event]
  B --> C[idle callback]
  C --> D[PostHog init]
  C --> E[header toggles + toaster hydrate]
  F[play pressed] --> G[narration MP3 downloads]
Loading

Spec: ADK-307

Changes

  • Show each narration length from the manifest and load the MP3 only on play (preload="none")
  • Cache /narration/* as immutable for one year
  • Start PostHog after the load event, without the exception, dead-click, and heatmap modules
  • Hydrate the header toggles and toaster through a new client:after-load directive
  • Inline the global stylesheet and add a 740 px candidate to the featured covers

Evidence

  • pnpm lighthouse (mobile)
    Before: not captured on this branch.
    After: home Performance 99, 100, 100; colophon 100, 100, 100. Accessibility, Best Practices, and SEO at 100. No render-blocking stylesheet on the home.
  • pnpm lighthouse --collect.settings.preset=desktop
    Before: not captured on this branch.
    After: Performance 100 on every run; image delivery lists no featured cover.
  • Home loaded in pnpm preview, network panel
    Before: array.js started at 286 ms, before the load event at 527 ms.
    After: no /narration/ request until play; array.js starts at 297 ms, after load at 125 ms; no dead-clicks-autocapture.js or exception-autocapture.js.
  • /colophon in pnpm preview
    Before: react started at 129 ms, before load at 301 ms.
    After: the React runtime starts at 163 ms, after load at 91 ms.
  • curl -sI on /narration/pt/hero.122702ad.mp3 and /_astro/toaster.CoN6vlss.js
    After: both return cache-control: public, max-age=31536000, immutable.

Merge risk

Door: two-way

Blast Radius: site-wide

Heatmaps stop collecting data, and the toggles and toaster become interactive slightly later on every page.

…-header-toggles' into adk-310-analytics-loads-on-idle-without-the-extra-capture-modules

* adk-307-load-performance-defer-narrations-analytics-and-header-toggles:
  perf: cache narration files as immutable
…-header-toggles' into adk-311-featured-covers-sized-to-their-slot

* adk-307-load-performance-defer-narrations-analytics-and-header-toggles:
  perf: cache narration files as immutable
…-header-toggles' into adk-308-narration-downloads-only-on-play-with-its-length-from-the-manifest

* adk-307-load-performance-defer-narrations-analytics-and-header-toggles:
  perf: cache narration files as immutable
…-header-toggles' into adk-312-global-stylesheet-inlined-in-the-page

* adk-307-load-performance-defer-narrations-analytics-and-header-toggles:
  perf: cache narration files as immutable
…-header-toggles' into adk-310-analytics-loads-on-idle-without-the-extra-capture-modules

* adk-307-load-performance-defer-narrations-analytics-and-header-toggles:
  feat: load narrations only on play with their length from the manifest
…-header-toggles' into adk-311-featured-covers-sized-to-their-slot

* adk-307-load-performance-defer-narrations-analytics-and-header-toggles:
  feat: load narrations only on play with their length from the manifest
  perf: start analytics on idle without the exception capture module
…-header-toggles' into adk-312-global-stylesheet-inlined-in-the-page

* adk-307-load-performance-defer-narrations-analytics-and-header-toggles:
  feat: load narrations only on play with their length from the manifest
  perf: start analytics on idle without the exception capture module
  fix: add the 740 px candidate to the featured cover widths
…-header-toggles' into adk-313-header-toggles-hydrate-on-idle

* adk-307-load-performance-defer-narrations-analytics-and-header-toggles:
  feat: load narrations only on play with their length from the manifest
  perf: inline the global stylesheet in the page
  perf: start analytics on idle without the exception capture module
  fix: add the 740 px candidate to the featured cover widths
  perf: cache narration files as immutable
Heatmaps enabled in the PostHog project settings load the dead-click module even with capture_dead_clicks off.
Astro's client:idle hydrates on the first idle callback, which the browser fires before the load event.
@adeonir
adeonir merged commit b33a6a0 into main Nov 14, 2026
6 checks passed
@adeonir
adeonir deleted the adk-307-load-performance-defer-narrations-analytics-and-header-toggles branch November 14, 2026 17:16
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.

1 participant