The user wants a browser performance budget.
I need to include specific metrics and techniques:
- Core Web Vitals Gates: LCP (Largest Contentful Paint), CLS (Cumulative Layout Shift), INP (Interaction to Next Paint).
- Optimization Strategies: Code splitting, Priority hints.
- Monitoring/Alerts: How to enforce this.
Structure of the Response:
A performance budget isn't just a list of numbers; it's a policy document. I should structure it as a formal proposal or a configuration file that could be used in a CI/CD pipeline, along with the rationale.
- Introduction: Briefly explain the goal (fast, responsive, stable UX).
- Section 1: The Gates (Metric Thresholds): Define "Good", "Needs Improvement", and "Fail" for LCP, CLS, and INP.
- Section 2: Implementation Strategies (How to stay within budget):
- Code Splitting: Rules for bundle sizes and lazy loading.
- Priority Hints: Rules for
fetchpriority.
- Section 3: Enforcement (Alerts & CI): Tools like Lighthouse CI or Webpack/Bundle analyzers.
- Section 4: Example Configuration: A concrete code snippet (e.g., JSON config for Lighthouse or a custom webpack setup).
Drafting Content - Details:
- LCP: Target < 2.5s. Budget < 1.2s (ambitious) or just stick to the standard "Good" threshold. Let's use the standard thresholds but maybe tighten them slightly for a "budget" (e.g., hard fail at 2.5s, warning at 2.0s).
- CLS: Target < 0.1. Hard fail at 0.1.
- INP: Target < 200ms. Hard fail at 200ms (since INP replaced FID).
- Code Splitting:
- Max bundle size per route? (e.g., 150KB JS).
- Max initial bundle size? (e.g., 300KB total).
- Priority Hints:
- LCP image:
fetchpriority="high".
- Third-party scripts:
fetchpriority="low" or async/defer.
- Alerts:
- CI failure on regression.
- Real User Monitoring (RUM) alerts (e.g., CrUX data drop).
Refining the "Draft" format:
I will present this as a Performance Budget Policy. It looks professional and actionable.
- Metric Name | Budget Threshold (Green) | Warning (Amber) | Fail (Red)
Section on Code Splitting:
Need to specify limits. "No single chunk > 150KB". "Total JS per page load < 300KB".
Section on Priority Hints:
Explicit rules on when to use high vs low.
Section on Alerts:
Slack/PagerDuty alerts for RUM data. CI blocking for PRs.
Reviewing against the prompt:
- LCP/CLS/INP gates included? Yes.
- Code split included? Yes.
- Priority hints included? Yes.
- Alerts included? Yes.
Let's write it out. I'll use Markdown for clarity.
Self-Correction during drafting: Initially, I might just list numbers. But a "budget" implies a workflow. I should add a "Governance" section—what happens when the budget is breached? (e.g., PR blocked).
INP Note: INP is the newer metric replacing FID. I must ensure I define the threshold correctly (200ms is the standard "good", 500ms is "poor"). I'll set the budget gate at 200ms.
Code Splitting: I should mention specific tools (Webpack, Vite, React.lazy) as examples of how, but focus the budget on the result (bundle sizes).
Priority Hints: Explain fetchpriority attribute usage.
Let's assemble the final output. I will provide a "Policy Document" format followed by a "CI Configuration" example.
Here is a comprehensive Browser Performance Budget Policy designed for a modern web application. This document defines the "Gates" (hard limits), implementation strategies, and alert protocols.
Browser Performance Budget Policy
Objective: To maintain a consistently fast, responsive, and stable user experience by enforcing strict limits on Core Web Vitals and network payload sizes.
1. The Gates (Metric Thresholds)
We enforce a "Pass/Warn/Fail" system. Pull Requests (PRs) that trigger a Fail status are blocked from merging.
A. Core Web Vitals (The User Experience Gates)
These metrics measure perceived user experience.
| Metric | Target (Green) | Warning (Amber) | Fail (Red) | Rationale |
|---|
| LCP (Largest Contentful Paint) | ≤ 2.0s | 2.0s – 2.5s | > 2.5s | Measures loading speed. Content must appear quickly. |
| INP (Interaction to Next Paint) | ≤ 150ms | 150ms – 200ms | > 200ms | Measures interactivity/responsiveness. Replaces FID. |
| CLS (Cumulative Layout Shift) | ≤ 0.05 | 0.05 – 0.1 | > 0.1 | Measures visual stability. No "jumping" elements. |
| TTFB (Time to First Byte) | ≤ 0.4s | 0.4s – 0.8s | > 0.8s | Server responsiveness must be fast to support LCP. |
B. Asset & Script Gates (The Weight Gates)
These limits prevent code bloat and main thread congestion.
| Resource Type | Budget Limit | Failure Condition |
|---|
| Total Page Weight | < 1.5 MB | Uncompressed assets exceed limit. |
| JavaScript (Compressed) | < 350 KB | Bundle size exceeds limit (First Load). |
| Critical Path JS | < 50 KB | Synchronous blocking scripts exceed limit. |
| Image Requests | < 100 KB/item | Any single image > 100KB not using next-gen formats. |
2. Implementation Strategy
To meet the gates above, the following architectural standards must be applied.
A. Code Splitting & Lazy Loading
To stay under the 350 KB JS Budget, we must avoid shipping the entire application code at once.
- Route-Based Splitting: Every distinct URL route must be a separate chunk.
- Component-Level Splitting: Heavy third-party libraries (e.g., heavy data visualization libraries like D3/Chart.js, PDF viewers, Markdown editors) must be dynamically imported (
import()) only when the user interacts with the component requiring them.
- Above the Fold Priority: Critical CSS and hero images for the current viewport must load synchronously. Everything below the fold must be deferred.
B. Priority Hints (fetchpriority)
We explicitly tell the browser which resources matter most to improve LCP.
- LCP Hero Images: The primary visual content (e.g., main product image, hero banner) must have
fetchpriority="high".
<img src="hero.webp" fetchpriority="high" />
- Non-Critical Scripts: Analytics, chat widgets, and non-essential trackers must have
fetchpriority="low" or be loaded via the defer attribute.
- Preconnect: Origins for critical third-party resources (e.g., CMS Headless API, CDN) must use
<link rel="preconnect">.
3. Monitoring & Alerts
Performance regression is treated with the same severity as a security vulnerability or a runtime bug.
A. CI/CD Enforcement (Pull Requests)
- Tool: Lighthouse CI / Webpack Bundle Analyzer.
- Action: On every commit, run Lighthouse against a static build.
- Rule: If LCP, CLS, or INP moves into the "Red" zone, OR if the JS bundle size increases by > 10KB without a specific "performance-override" flag, the Build Fails.
B. Synthetic Monitoring (Scheduled)
- Tool: Calibre / SpeedCurve / WebPageTest.
- Frequency: Hourly runs on Production (mobile & desktop profiles).
- Action: Detect "regression" (e.g., a deploy that added 200ms to LCP).
C. Real User Monitoring (RUM)
- Tool: Sentry / DataDog / Vercel Analytics.
- Action: Monitor the 75th percentile (p75) of real user data.
- Alert Channel: Slack (
#dev-performance).
- Example Alert: "⚠️ LCP Regression Detected: Mobile p75 LCP has risen to 3.1s (Threshold: 2.5s) in the last 30 minutes."
4. Incident Response Protocol
If an alert fires or a budget gate is breached:
- P1 (Critical): If LCP > 4s or INP > 500ms, page the on-call engineer. This indicates the site is unusable for a significant portion of users.
- P2 (High): If a bundle size check fails in CI, the developer must either:
- Optimize the code (remove dependencies, split chunks).
- Request a budget increase (requires Tech Lead approval) if the feature is critical.
- Remediation: Roll back the offending deploy if RUM metrics degrade > 20% compared to the previous baseline.