# Performance Budget Configuration
# =================================
# This YAML defines gates (hard blocks for CI/CD deploys) and alerts (warnings/notifications)
# for Core Web Vitals: LCP, CLS, INP.
#
# Usage:
# - Integrate with Lighthouse CI (lighthouserc.json + GitHub Actions/Netlify)
# - Or Web Vitals JS library + Sentry/New Relic for runtime monitoring.
# - Gates: Fail build if exceeded (e.g., Lighthouse CI assertions).
# - Alerts: Notify Slack/Email if approaching (e.g., >80% of gate).
#
# Metrics Reference (Google CWV):
# - LCP: Largest Contentful Paint (loading perf) | Good: ≤2.5s
# - CLS: Cumulative Layout Shift (visual stability) | Good: ≤0.1
# - INP: Interaction to Next Paint (responsiveness) | Good: ≤200ms
#
# Budgets tuned conservatively for 75th percentile field data (CrUX).
perfBudget:
# Field Data Thresholds (75th percentile from CrUX/SpeedCurve/Sentry)
fieldData:
lcp: 2.5 # Gate: ≤2.5s (fail deploy); Alert: >2.0s
cls: 0.1 # Gate: ≤0.1; Alert: >0.08
inp: 200 # Gate: ≤200ms; Alert: >160ms
# Lab Data Thresholds (Lighthouse audits - faster, for CI)
labData:
lcp: 2.3 # Gate: ≤2.3s; Alert: >1.8s
cls: 0.08 # Gate: ≤0.08; Alert: >0.06
inp: 180 # Gate: ≤180ms; Alert: >144ms
gates:
# Hard fail conditions (e.g., Lighthouse CI --assert)
lcp:
gate: 2500 # ms - Block deploy if LCP >2.5s
alert: 2000 # ms - Warn if >2.0s
cls:
gate: 0.1
alert: 0.08
inp:
gate: 200 # ms
alert: 160 # ms
alerts:
# Slack/Email thresholds (e.g., via SpeedCurve/Sentry monitors)
regressionThreshold: 20 # % - Alert on >20% regression from baseline
baselineUrls: # Compare against these URLs
- https://example.com/
- https://example.com/product/
Implementation Guide
1. Lighthouse CI (Recommended for CI/CD Gates)
Install: npm i -D @lhci/cli
lighthouserc.json (assertions from above):
{
"ci": {
"collect": {
"numberOfRuns": 5,
"url": ["https://example.com/"]
},
"assert": {
"preset": "lighthouse:no-pwa",
"assertions": {
"largest-contentful-paint": ["warn", {"maxNumericValue": 2300}],
"cumulative-layout-shift": ["error", {"maxNumericValue": 0.08, "aggregationMethod": "optimistic"}],
"interaction-to-next-paint": ["error", {"maxNumericValue": 180}]
}
},
"upload": {
"target": "github"
}
}
}
GitHub Actions Example (.github/workflows/perf.yml):
name: Perf Budget Gates
on: [pull_request]
jobs:
lighthouse:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: lighthouse-ci/action@v5
with:
configPath: lighthouserc.json
2. Runtime Monitoring (Field Data Alerts)
- web-vitals JS lib (client-side):
import { onLCP, onCLS, onINP, Metric } from 'web-vitals';
function sendToSentry(metric: Metric) {
if (metric.value > thresholds[metric.name].alert) {
Sentry.captureMessage(`Perf Alert: ${metric.name} = ${metric.value}ms`, 'warning');
}
}
onLCP(sendToSentry); onCLS(sendToSentry); onINP(sendToSentry);
- Tools: Sentry Web Vitals, SpeedCurve, New Relic Browser – Set alerts on 75th percentile.
3. Customization Tips
- Mobile-first: Tighten budgets 20% for mobile (e.g., LCP gate: 3s).
- Baselines: Use Chrome UX Report (CrUX) dashboard for your domain's 75th percentile.
- Polyfill INP: For older browsers, use
First Input Delay (FID) fallback.
- Debug: Run
lhci autorun locally.
This setup enforces perf as code – deploys halt on regressions, alerts catch issues early. Need tweaks for your stack? Provide more details! 🕵️♂️