Browser performance budgets: LCP/CLS/INP gates, code splitting, font/image policy, alerts.
- User
Browser performance budgets: LCP/CLS/INP gates, code splitting, font/image policy, alerts.
- Assistant
1) Web performance budgets (what we gate on)
Scope: Each “key page type” (e.g., marketing landing, logged-in dashboard, checkout) must meet budgets. Budgets are evaluated primarily on mobile.
Core Web Vitals gates (field/RUM targets)
Use p75 (75th percentile) over a rolling window (e.g., 7 days) for real users.
Metric Pass (gate) Warning Fail LCP ≤ 2.5s 2.5–4.0s > 4.0s CLS ≤ 0.10 0.10–0.25 > 0.25 INP ≤ 200ms 200–500ms > 500ms Operational rule:
- Block release if any key page type is in Fail at p75 for ≥24h (or after sufficient sample size).
- Block merge if synthetic/CI indicates a regression likely to push field into Warning/Fail (details below).
Synthetic (CI) gates (to catch regressions early)
Run Lighthouse (or equivalent) on:
- Mobile emulation (e.g., Moto G4 / mid-tier), 4G throttling, cold cache.
- 3–5 runs; gate on median (and optionally “max” for flake control).
Recommended CI thresholds (tunable per app):
- LCP ≤ 2.5–3.0s (synthetic often needs a little headroom)
- CLS ≤ 0.10
- INP is not reliably captured by Lighthouse in the same way as field INP; in CI also gate on TBT ≤ 200ms as a proxy.
- Add: TTFB ≤ 800ms (server-side health) and Total JS execution time if available.
2) Code splitting / JS delivery policy
Non-negotiables
- Route-level splitting: Each route/page gets its own chunk; avoid “one big app bundle”.
- Component-level splitting for expensive UI: Use
import()for heavy widgets (charts, editors, maps), gated behind visibility/interaction. - No above-the-fold waterfalls: Don’t lazy-load something needed for initial render without a placeholder strategy; avoid nested dynamic imports that serialize.
- Keep the critical path small: Only ship what’s needed to render the initial viewport and achieve LCP.
Practical budgets (initial load, per route)
(Choose numbers appropriate to your product; these are common starting points.)
- Initial JS (per route): ≤ 170–250 KB gzip (or ≤ 600–800 KB “raw”)
- Initial CSS: ≤ 50 KB gzip
- # of initial requests: minimize; aim ≤ 60 (HTTP/2+) and keep critical chain short.
Enforcement tooling
- Bundle size gates:
size-limit,bundlesize, or build-tool budgets. - Bundle analysis required on PRs that add dependencies or increase JS by >X%.
Example
size-limit:{ "size-limit": [ { "path": "dist/assets/app-*.js", "limit": "250 KB" }, { "path": "dist/assets/vendor-*.js", "limit": "200 KB" }, { "path": "dist/assets/app-*.css", "limit": "50 KB" } ] }Dependency policy
- Any new third-party dependency must declare:
- purpose, alternative considered, and measured size/runtime impact
- whether it runs on initial load
- Prefer native APIs, smaller libs, and tree-shakeable ESM packages.
3) Font policy (LCP/CLS-safe)
Goals
- Avoid FOIT/flash-induced CLS
- Minimize font bytes and blocking behavior
Rules
- Limit families/weights: Ideally 1 family, ≤2 weights (or use a variable font).
- WOFF2 only (WOFF fallback only if required).
- Self-host fonts when possible (cache control + privacy + fewer connections).
- Subset fonts (unicode-range, glyph subsetting) and ship only needed scripts.
font-display: swap(oroptionalfor non-critical fonts).- Preload only critical fonts used above the fold; don’t preload everything.
Example:
<link rel="preload" href="/fonts/Inter.var.woff2" as="font" type="font/woff2" crossorigin>@font-face { font-family: "Inter"; src: url("/fonts/Inter.var.woff2") format("woff2-variations"); font-display: swap; }CLS guard: Ensure fallback font metrics are compatible (consider
size-adjust,ascent-override, etc., if CLS from font swap is observed).
4) Image policy (LCP-first, CLS-safe)
Rules
- Always set dimensions (
width/heightor CSS aspect-ratio) to prevent CLS. - Use responsive images:
srcset+sizes. - Modern formats: AVIF first, WebP next, JPEG/PNG fallback when needed.
- Lazy-load below the fold:
loading="lazy"+decoding="async". - Prioritize LCP image:
- do not lazy-load it
- use
fetchpriority="high"or framework equivalent - consider
preloadif it’s reliably the LCP element
- CDN required for resizing/compression (or build-time optimization).
Example LCP image:
<img src="/img/hero-1200.avif" srcset="/img/hero-800.avif 800w, /img/hero-1200.avif 1200w" sizes="(max-width: 600px) 90vw, 1200px" width="1200" height="600" fetchpriority="high" decoding="async" alt="" />CLS policy: Never insert banners/toolbars above existing content without reserving space. For dynamic content, reserve slots/skeletons with fixed dimensions.
5) Alerts & monitoring (field + release safety)
RUM (field) collection
- Capture Web Vitals with
web-vitalsand send to your analytics endpoint tagged by:- page type/route
- release version/commit SHA
- device class (mobile/desktop)
- connection type (optional)
Alert conditions (recommended):
- Regression alert: p75 worsens by ≥10% (or ≥200ms LCP / ≥0.02 CLS / ≥50ms INP) vs previous release baseline.
- Budget breach alert: p75 crosses into Warning for ≥2 hours; Fail for ≥30 minutes (tune to volume).
CI / pre-merge alerts
- Lighthouse CI (or equivalent) runs on PRs:
- If any metric crosses the CI threshold, fail the check.
- If delta vs main is above regression threshold, fail (even if still under absolute cap).
Example Lighthouse CI intent (pseudo-config):
- run 5 times, take median
- fail if LCP > 3000ms, CLS > 0.10, TBT > 200ms
- fail if LCP increases by > 300ms vs main
Ownership & routing
- Alerts go to:
#perf-alerts+ on-call if “Fail”. - Each key page type has an explicit owner (team/service).
Exception process
- Temporary override allowed only with:
- owner approval
- ticket created
- expiry date (e.g., 14 days)
- mitigation plan
6) Recommended “Definition of Done” for performance-sensitive PRs
- Meets CI gates (Lighthouse + bundle sizes).
- If JS/CSS increases > threshold: attach bundle diff and justification.
- No new CLS sources (images without dimensions, injected UI without reserved space, late-loading fonts).
- If it affects LCP element: verify LCP resource priority (not lazy, correct caching, compressed).
If you tell me your stack (Next.js/Vite/Webpack, SSR vs SPA), key page types, and your target device/network (e.g., “mid-tier Android on 4G”), I can turn this into concrete numbers + exact configs (Lighthouse CI YAML, size-limit rules, and a
web-vitalsbeacon snippet) that match your environment.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.