perf(marketing): cut critical-path payload to raise Lighthouse performance score

Merged
KI
3mo ago
+310-226

Summary

Homepage was the one Lighthouse category not at 100 (Performance 79 in the report, 75 reproducible locally). The failing metric was LCP alone — everything else was already ~1.0. This PR removes ~500KiB from the critical rendering path with no visual or functional change:

  • Fonts (~150KiB): geist/font/pixel instantiates all five GeistPixel faces at module scope, so importing two preloaded five files — and none were used anywhere. Pixelify Sans was also unused. Both removed; Micro5 moved into /team (its only consumer). IBM Plex Mono keeps display: swap but drops preload since it's not the LCP font.
  • Analytics (~204KiB): posthog-js + Sentry were the largest initial chunk via instrumentation-client.ts. Both now dynamic-import after window load (or first interaction, whichever comes first); call sites queue through lib/analytics/lazy withPosthog() so no events are lost. Unused PostHogProvider removed.
  • Ad pixels (~175KiB): gtag + Reddit pixel moved afterInteractive → lazyOnload.
  • framer-motion: switched to LazyMotion + m.* app-wide; the animation feature bundle loads as an async chunk.

Results (CDP-attached Lighthouse, prod build, medians of repeated runs)

beforeafter
Mobile simulated7582 (stable ×3)
Desktop98100
Mobile devtools-throttled (real UX)—94–97, LCP 1.9s

Note: simulated-mobile on prod swings 78–93 run-to-run on identical code (Lantern extrapolates from the observed trace), so judge post-deploy PSI by median of several runs. Remaining gap to a guaranteed 90 is structural (React hydration payload counted against LCP by the simulator); closing it needs design trade-offs (Inter opsz, de-hydrating the hero).

Verification

  • Analytics confirmed firing in Lighthouse traces: posthog /ingest/e/, Reddit PageVisit, gtag conversion
  • All 12 top-level routes 200 on the prod build; homepage + /team screenshots visually unchanged (typewriter, boids, mockup, Micro5 on /team)
  • Best Practices 77 on this Lighthouse version is identical on unchanged prod (ad-pixel third-party cookies etc.) — pre-existing, not from this PR
  • lint + typecheck clean

Summary by cubic

Defers analytics (posthog-js and @sentry/nextjs), ad pixels, and framer-motion features and removes unused fonts to cut critical‑path payload and improve LCP. Previously these assets loaded before first paint; now they load after window load or first interaction, with early analytics calls queued, raising Lighthouse Performance without visual changes.

Migration and review notes

  • Do not import posthog-js directly. Use track() and withPosthog(callback) from lib/analytics; analytics initialize lazily in instrumentation-client.ts. Remove/avoid PostHogProvider.
  • Use m.* instead of motion.* and keep the app wrapped in <LazyMotion> (configured in providers.tsx) so the framer-motion feature bundle loads async.
  • Fonts: Micro_5 is now loaded only on /team. Import any non‑LCP fonts per page as needed; IBM Plex Mono remains but is not preloaded. Do not reintroduce font preloads for non‑LCP text.
  • Ad/marketing tags use lazyOnload. Apply the same strategy for new tags.
  • Use onRouterTransitionStart() from instrumentation-client if needed; it no‑ops until Sentry initializes.

Summary by CodeRabbit

  • Performance

    • Improved marketing-page loading by deferring animation features, analytics, advertising, and error monitoring until needed.
    • Reduced unnecessary font preloading and optimized page resource usage.
  • Analytics

    • Improved reliability of signup and cookie-consent tracking, including support for visitors who previously opted out.
  • Visual Experience

    • Preserved existing animations, FAQ interactions, demonstrations, navigation, and page content without changing their appearance or behavior.
  • Typography

    • Updated the team page to load and apply its intended display font.