Getting a content-heavy storefront from 45 to 90 on Lighthouse Mobile is mostly subtraction: remove dead third-party apps, compress hero photography, and stop blocking first paint. Getting from 95 to a sustained 100/100 on throttled Moto G4 emulation is a different discipline. Every remaining point hides in font metric drift, unpurged CSS variables, compression overhead on the SSR boundary, and an edge-injected analytics script most teams do not even realize is running.

This is the production playbook distilled from our headless storefront re-architecture and deployed across our React Router v7 and Shopify Hydrogen builds.

Measured Mobile Lighthouse progression (4G slow throttling, 4x CPU slowdown)
MetricLegacy BaselineProduction Architecture
Lighthouse Mobile Score45 / 100100 / 100
Largest Contentful Paint (LCP)5.2 s0.9 s
Total Blocking Time (TBT)1,140 ms0 ms
Cumulative Layout Shift (CLS)0.1840.000
Critical CSS Transfer186 KB external14 KB inline gzip
Legacy JS Polyfill Audit10.2 KiB warning (99 cap)0 KiB via Faro

1. Self-Hosted WOFF2 and Zero-CLS Metrics via Tipo

External font CDNs (use.typekit.net, Google Fonts, or origin Shopify domains) pay two taxes on mobile: an extra TLS handshake before the stylesheet even arrives, and a layout shift when the real face swaps over the platform fallback. Moving every active weight into local /fonts/*.woff2 assets solves the connection waterfall, but font-display: swap alone still causes 0.04–0.12 CLS when headline wrapping changes by a single line.

To lock glyph geometry before the WOFF2 finishes decoding, I wrote roier/tipo (test it live in Roier Lab)—a pure-TypeScript OpenType/WOFF2 table parser with zero WASM that reads head, hhea, OS/2, and hmtx advance widths to compute exact CSS descriptor overrides against a local system font.

app/fonts.csscss
@font-face {
  font-family: "Ginto Nord Fallback";
  src: local("Arial Black"), local("Helvetica Neue"), local("Arial");
  size-adjust: 108.4%;
  ascent-override: 86.2%;
  descent-override: 21.5%;
  line-gap-override: 0%;
}

@font-face {
  font-family: "Ginto Nord";
  src: url("/fonts/ginto-nord-900.woff2") format("woff2");
  font-weight: 900;
  font-style: normal;
  font-display: swap;
}
Generated by Tipo so the fallback advance width and vertical metrics match Ginto Nord within sub-pixel tolerance, pinning CLS to 0.000.

2. Build-Time CSS Tree-Shaking and SSR Inlining

Even a single <link rel="stylesheet" href="/assets/app.css"> stalls First Contentful Paint for a full round trip. Worse, default utility presets emit thousands of unused --colors-* custom properties that bloat both parse time and wire size.

  • Strip unused token palettes at config resolution: In panda.config.ts, prune unused default color scales inside hooks['config:resolved'] with minify: true and hash: true enabled.
  • Inline purged critical CSS directly in SSR `<head>`: Import the compiled CSS string on the server and emit <style id="ssr-master-css"> once, then read document.getElementById('ssr-master-css')?.innerHTML during client hydration so zero stylesheet bytes are duplicated in window.__reactRouterContext.
  • Keep catalog HTML and reviews strictly server-only: Any .server.ts module stays out of client bundles. On mobile, secondary hover photos on product cards hydrate via data-hover-src only after desktop pointermove, cutting card image bytes in half.

3. Bun Runtime and Pre-Compressed Zstd / Brotli / Gzip SSR

Once external CSS and font waterfalls disappear, Time to First Byte and compressed transfer size dictate LCP. Running the production server on Bun cuts cold-start latency and per-request overhead compared to Node on Cloud Run, while letting us serve pre-compressed static bundles (.zst, .br, .gz) directly from memory and compress dynamic SSR streams cleanly based on Accept-Encoding.

server.tsts
import { brotliCompressSync, constants, gzipSync } from "node:zlib";

function negotiateStaticPath(pathname: string, acceptEncoding: string) {
  if (acceptEncoding.includes("zstd") && staticIndex.has(`${pathname}.zst`)) {
    return { path: `${pathname}.zst`, encoding: "zstd" as const };
  }
  if (acceptEncoding.includes("br") && staticIndex.has(`${pathname}.br`)) {
    return { path: `${pathname}.br`, encoding: "br" as const };
  }
  if (acceptEncoding.includes("gzip") && staticIndex.has(`${pathname}.gz`)) {
    return { path: `${pathname}.gz`, encoding: "gzip" as const };
  }
  return { path: pathname, encoding: null };
}

export function compressSsrPayload(
  html: Uint8Array,
  acceptEncoding: string,
): { body: Uint8Array; encoding: "br" | "gzip" | null } {
  if (html.byteLength < 1024) return { body: html, encoding: null };
  if (acceptEncoding.includes("br")) {
    return {
      body: brotliCompressSync(html, {
        params: { [constants.BROTLI_PARAM_QUALITY]: 5 },
      }),
      encoding: "br",
    };
  }
  if (acceptEncoding.includes("gzip")) {
    return { body: gzipSync(html, { level: 6 }), encoding: "gzip" };
  }
  return { body: html, encoding: null };
}
Pre-compressed static assets skip runtime CPU entirely; dynamic SSR HTML uses Brotli quality 5 (sub-2ms compression on 25 KB HTML) with Gzip level 6 fallback.

Notice the Brotli quality setting (5, not 11). Quality 11 belongs strictly in the Docker build step for static assets. Running Brotli 11 synchronously on every SSR response adds 25–45 ms to TTFB for less than 400 bytes of savings. Quality 5 hits the knee of the curve: ~18% smaller than Gzip level 6 at ~1.4 ms server time.

4. Breaking the 99 → 100 Cap: Stripping Cloudflare's Beacon

After every font, stylesheet, image, and SSR stream was dialed in, our production storefronts behind Cloudflare still plateaued at 99/100 Mobile with a single red flag in Lighthouse: Avoid serving legacy JavaScript to modern browsers (10.2 KiB).

The culprit was not our code. When Cloudflare Web Analytics RUM is auto-injected at the edge, Cloudflare appends https://static.cloudflareinsights.com/beacon.min.js. That bundle ships guarded ES polyfills (Array.prototype.at, Array.prototype.findLast, Array.prototype.includes, and Object.hasOwn) that Lighthouse flags unconditionally because they sit on the critical third-party script trace.

app/root.tsxtsx
{cfBeaconToken ? (
  <script
    defer
    src="/metrics.js"
    data-cf-beacon={JSON.stringify({
      token: cfBeaconToken,
      send: { to: "/cdn-cgi/rum" },
    })}
  />
) : null}
First-party telemetry without a cross-origin handshake or legacy polyfill penalty. Always verify live HTML with a mobile Chrome User-Agent, because Cloudflare suppresses auto-injection for default curl UAs.

With /metrics.js served from the same origin and beacon.min.js absent from the HTML, Lighthouse's Legacy JavaScript warning drops to 0 KiB, Real User Monitoring stays intact in the Cloudflare dashboard, and Mobile Performance locks cleanly at 100/100. You can inspect the exact stripped AST patterns or generate a Cloudflare Worker directly in Roier Lab → Faro.