← All posts

· 7 min read

Chasing 100s: Lighthouse Performance on a Real SSR App

Why Lighthouse on a real app is harder than the tutorials suggest

Most Lighthouse "score 100" guides work from a minimal example — a static page with a single stylesheet and no JavaScript. A production SSR app has real constraints: a UI library, fonts, dynamic content, analytics, a service worker, and a server round-trip in the hot path. Getting to 100 on desktop and close on mobile requires understanding which metrics you are actually affecting and why.

The metrics that matter for an SSR app

Lighthouse reports six core metrics, but two dominate the performance score for a content-heavy SSR site:

  • Largest Contentful Paint (LCP) — how quickly the main content is visible. For a blog page, this is usually the article heading or hero image.
  • Total Blocking Time (TBT) — the sum of time the main thread is blocked during page load. Long JavaScript parsing and execution tasks drive this up.

First Contentful Paint and Speed Index track closely with LCP for SSR apps (since the server sends real HTML). Cumulative Layout Shift (CLS) is a separate concern — mostly a CSS hygiene issue.

Font loading: the LCP killer

Web fonts are render-blocking when loaded naively. The two rules that matter most:

  1. Preload the font file for the LCP element's typeface. A <link rel="preload" as="font"> in the <head> tells the browser to fetch the font at top priority, before it discovers it in the CSS.
  2. Use only the Unicode subsets the page actually needs. Preloading a Latin-extended subset when the page uses only basic Latin glyphs wastes bandwidth and delays the font swap.

One trap worth noting: preloading extra font subsets that are not used on the page actually hurts LCP. The browser prioritises the preloaded resource, consuming bandwidth that could have gone to the actual content. Measure before adding preloads.

CSS-in-JS and the critical CSS path

MUI with Emotion generates styles at render time. In SSR mode, the pattern is:

  1. Render the component tree server-side, collecting all generated CSS
  2. Embed that CSS inline in the <head> of the HTML response
  3. On the client, Emotion recognises the injected styles and skips regeneration

This eliminates the Flash of Unstyled Content (FOUC) and removes the blocking stylesheet fetch. The tradeoff is a larger HTML document — but for an SSR app, sending a fully-styled document in the first response is the correct tradeoff.

TBT: JavaScript bundle size

TBT is driven by long tasks during JavaScript parse and execution. For a React + MUI app, the main bundle is unavoidably large. The strategies that helped:

  • Route-level code splitting: each route is a dynamic import. The browser only parses the current page's code, not the entire app.
  • Deferring analytics initialisation: analytics setup runs after DOMContentLoaded, not on the critical path.
  • MUI tree shaking: importing components from their specific paths (e.g. @mui/material/Button) lets Vite tree-shake unused parts of MUI. Named imports from @mui/material also work with modern bundlers, but the explicit path import is more predictable.

The mobile throttling ceiling

Lighthouse mobile simulates a mid-tier Android device with 4× CPU throttling and slow 4G. Some TBT is genuinely irreducible at that throttle level for an app that depends on a large UI framework. A score in the low-to-mid 90s on mobile, while 100 on desktop, is a real and documented ceiling for apps using MUI — not a bug or a configuration mistake.

The useful question is not "how do I get 100 on mobile" but "is my mobile score stable across runs, and is it within the expected range for this stack?" Unexplained regressions are worth investigating; the theoretical maximum is not always 100.

CLS: reserve space for dynamic content

Layout shifts are usually caused by content that changes size after the initial render: images without explicit dimensions, fonts swapping from a fallback to the web font, or components that expand when data arrives. Fixing CLS is mostly a matter of adding explicit width/height attributes to images, using font-display: swap with a closely-matched fallback font, and sizing skeleton loaders to match the real content they replace.