Skip to content

Explore ways to improve first-load performance #516

Open

Description

@stephaniehobson

Ensemble is a client-rendered SPA. index.html has an empty #root, so the first paint and LCP wait for JS to download, parse and fetch data. Below are routes worth exploring. Start by measuring a baseline: Lighthouse / WebPageTest on / and /dashboard/user-activity, throttled to mobile, cold and warm cache. Record LCP, CLS, TBT and the request waterfall.

Render-blocking requests

  • index-*.js (~214 KB raw) and index-*.css (~14 KB) both block rendering. Check what the entry bundle holds: npm run size. react-ga4/gtag, react-helmet-async, react-router and markdown-it are candidates to defer or trim.
  • withTracker.jsx calls ReactGA.initialize at import time. Confirm the gtag script is async and doesn't compete with critical requests. Consider initialising it after load.
  • Inline the critical CSS for the header/shell in index.html, or check that each route's CSS chunk (Home-*.css, DashboardContainer-*.css) doesn't add a blocking round trip after its JS chunk.

Network dependencies (request chains)

  • Cold dashboard waterfall today: index.html → index.js → DashboardContainer chunk (~178 KB) → ${source}/index.json → N × per-metric index.json → charts render. ChartContainer (~268 KB, Observable Plot) is already loaded up front (Layout shifts as graphs load #509).
  • Add <link rel="modulepreload"> for the route chunk and <link rel="preload" as="fetch" crossorigin> for the dashboard index.json. Each copy of index.html per route path is a natural place for this. Vite could emit per-route HTML at build time.
  • Start the dashboard index.json fetch in parallel with the chunk load, rather than after DashboardContainer mounts. For example, warm lib/fetchCache.js from Main.jsx.
  • Ask the transposer whether the dashboard index could inline the summary/first metric to cut a round trip.
  • Caching: docs/architecture/deploy.md notes that the CDN rewrites cache-control to public,max-age=0, so the immutable hashed assets get revalidated on every visit. Raise this with the CDN owners (Terraform FORCE_CACHE_ALL). Also confirm that brotli/gzip compression and HTTP/2/3 are on.

Font display

  • Application.styl declares 8 Fira Sans @font-face rules with WOFF/TTF/SVG sources (no WOFF2) and no font-display. Unused .eot files ship in the repo.
  • The 468--fresh-paint branch switches to Mozilla Headline/Text WOFF2, which already moves to WOFF2. Fold this work into that branch rather than optimising Fira.
  • Add font-display: swap (or optional) and preload the one or two weights used above the fold. Consider size-adjust/ascent-override on the fallback to limit swap shift. Check how many weights and styles the pages actually use.

Layout shifts

  • Measure CLS on cold loads. Layout shifts as graphs load #509 added same-size placeholders for metrics. Check whether any remaining shifts come from the header/footer jumping when main goes from empty → spinner → dashboard, the font swap, the region selector and dates arriving, or the "Proceed to …" button appearing late.
  • Spinner waits 1 s before showing dots. Confirm its container reserves the final height.

Page skeletons

  • Today: route chunk → LazyBoundary spinner; dashboard → Spinner ("Loading dashboard"); metrics → MetricOverviewPlaceholder / SummaryMetricPlaceholder (striped header + spinner).
  • Put a static app-shell skeleton (header, nav, footer, page title area) into index.html's #root, replaced on first render, so something meaningful paints before JS.
  • Swap the dashboard-level spinner for a skeleton built from config.json (title, section layout), so the page structure shows before index.json arrives.
  • Keep the role="status" announcements and the focus handling in Main.jsx working with any skeleton.

Rehydration / prerendering

  • There's no SSR, so nothing gets rehydrated today. Explore build-time prerendering of /, /contact and each /dashboard/<key> shell (Vite SSG or a small Node prerender script). The deploy already writes an HTML file per route. Then switch from createRoot to hydrateRoot.
  • Risks: Application.jsx reads window.location.href, sessionStorage region is only known on the client, and live data changes weekly. Prerender the shell only, not the data, and watch for hydration mismatches.
  • Bonus: the <noscript> experience and metadata improve (og:title without JS).

Bundle / main-thread

  • Check the entry and dashboard chunk sizes with npm run size. Look at d3 and Observable Plot duplication, distinct-colors, dateformat, and react-spinners. Check whether the ChartContainer preload delays interactivity on /.
  • Profile long tasks during chart render on mobile CPU throttling.

Guardrails

  • Consider a Lighthouse CI or Playwright perf budget (CLS, bundle size) in ci.yml once there's a baseline.

Activity

  1. stephaniehobson commented on Nov 19, 2026

    @stephaniehobson
    CollaboratorAuthor

    Measured and partly fixed in #518. Figures are medians of 5 cold loads of a local production build, on a simulated phone (Slow 4G, 4× CPU, 412×915):

    page FCP LCP CLS
    / 1684 → 1288 ms 2240 → 2088 ms 0.686 → 0.000
    /dashboard/user-activity 1684 → 1288 ms 5704 → 3680 ms 0.098 → 0.000

    What made the difference, by area from the original list:

    • Network dependencies: the dashboard's data is requested at startup instead of after its 178 KB chunk. This was the largest single gain.
    • Render-blocking requests: the route chunks are preloaded with the main script. Preloading everything, or the chart chunk and fonts too, made every number worse on a slow connection.
    • Page skeletons: a static header in index.html paints before any JavaScript runs.
    • Layout shifts: main stays a window tall while a page loads, which fixes a 0.53 footer jump on / that production has today. The "Proceed to" button now waits for its dashboard.
    • Font display: size-adjusted Arial fallbacks stop text moving when the Mozilla fonts arrive. This builds on Fresh paint: Firefox fonts and purples, updated footer, accessible links #512's WOFF2 and font-display: swap.
    • Rehydration: not started. There's no server rendering to rehydrate. Prerendering on top of the new shell is a follow-up.

    Not loaded any more: gtag for the placeholder G-XXXXXXXXXX ID, which production loads today.

    The biggest remaining cost is that production serves every script and stylesheet uncompressed (214 KB against 71 KB gzipped for the main script). That's #517.

    Other follow-ups, not started:

    • Request the dashboard data from the HTML itself, which needs per-route HTML.
    • Trim markdown-it and its dependencies (about 90 KB of the dashboard chunk) and chroma-js (41 KB of the chart chunk).
    • Subset Mozilla Headline.
    • Prerender and hydrate.
    • A skeleton for the dashboard itself.
    • A CI performance budget.

    The measurements and the reasoning are in docs/execplans/2026-11-18-first-load-performance.md.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions