3 Hours

12. Performance Budgets: Setting and Enforcing Limits

Performance

Performance budgets are limits on bundle size, load time, and other performance metrics. This module covers setting and enforcing performance budgets in your build pipeline.

The key insight is that performance budgets prevent performance regression. They catch size increases before they reach production. Understanding performance budgets is essential for maintaining performance over time.

This module covers setting budgets, enforcing budgets in CI/CD, and monitoring performance.

Setting Performance Budgets

Performance budgets should be based on: bundle size (JavaScript, CSS), image size, load time (First Contentful Paint, Time to Interactive), and other metrics. Budgets should be realistic and based on user expectations.

Common budgets: total bundle size under 200KB, CSS under 50KB, images under 1MB, FCP under 1.5s, TTI under 3s. Budgets should be reviewed and adjusted regularly.

Try It Yourself: Enforcing Budgets

Follow these steps to enforce performance budgets.

Step 1: Install budget tools
npm install --save-dev bundlesize<br>npm install --save-dev @percy/cli

Step 2: Configure budgets
// package.json<br><strong><code>bundlesize: [
{
path: dist/index.js,
maxSize: 200 kB
},
{
path: dist/vendor.js,
maxSize: 100 kB
},
{
path: dist/*.css,
maxSize: 50 kB
}
]

Step 3: Add to CI/CD
# .github/workflows/performance.yml<br>name: Performance Budget<br><br>on: [pull_request]<br><br>jobs:<br> budget:<br> runs-on: ubuntu-latest<br> steps:<br> - uses: actions/checkout@v4<br> - run: npm install<br> - run: npm run build<br> - run: npx bundlesize

Step 4: Review and adjust
Review budget violations and adjust as needed.

Try It Yourself: Set performance budgets for a project. Enforce them in CI/CD.

Knowledge Check

Ready to test your understanding of 12. Performance Budgets: Setting and Enforcing Limits?

Back