Using performance budgets | lighthouse-php | Spatie

 SPATIE

  Lighthouse PHP
=================

spatie.be/open-source

  [Docs](https://spatie.be/docs)  [Lighthouse-php](https://spatie.be/docs/lighthouse-php/v2)  Usage  Using performance budgets

 Version   v2

 Other versions for crawler [v2](https://spatie.be/docs/lighthouse-php/v2)

- [ Introduction ](https://spatie.be/docs/lighthouse-php/v2/introduction)
- [ Support us ](https://spatie.be/docs/lighthouse-php/v2/support-us)
- [ Requirements ](https://spatie.be/docs/lighthouse-php/v2/requirements)
- [ Installation &amp; setup ](https://spatie.be/docs/lighthouse-php/v2/installation-setup)
- [ Questions and issues ](https://spatie.be/docs/lighthouse-php/v2/questions-issues)
- [ Changelog ](https://spatie.be/docs/lighthouse-php/v2/changelog)
- [ About us ](https://spatie.be/docs/lighthouse-php/v2/about-us)

Usage
-----

- [ Generating your first report ](https://spatie.be/docs/lighthouse-php/v2/usage/generating-your-first-report)
- [ Configuring a run ](https://spatie.be/docs/lighthouse-php/v2/usage/configuring-a-run)
- [ Working with results ](https://spatie.be/docs/lighthouse-php/v2/usage/working-with-results)
- [ Saving an HTML report ](https://spatie.be/docs/lighthouse-php/v2/usage/saving-an-html-report)
- [ Using performance budgets ](https://spatie.be/docs/lighthouse-php/v2/usage/using-performance-budgets)

 Using performance budgets
=========================

Lighthouse has an interesting feature where you can specify so-called budgets. You can, for example, specify the maximum amount of time for the 'time to interactive' metric, or the maximum amount (measured in Kb) of JavaScript your page may contain.

You can learn more on this feature in the 'Use Lighthouse for performance budgets [at web.dev](https://web.dev/use-lighthouse-for-performance-budgets/).

You can pass your performance budget as an array to the `budgets()` method.

```
$result = Lighthouse::url($url)
    ->budgets([
        [
            'timings' => [
                [
                    'metric' => 'interactive',
                    'budget' => 5000,
                ],
            ],
        ],
    ])
    ->run();
```

In the [HTML report](/docs/lighthouse-php/v2/usage/saving-an-html-report), you can see the results of your budget.

![screenshot](https://spatie.be/docs/lighthouse-php/v2/images/budget.jpg).

You can get an array with the results of the budget calling `budgetResults()`.

```
$result->budgetResults();
```

It will return an array much like this one:

```
[
    'performance-budget' => [
        'id' => 'performance-budget',
        'title' => 'Performance budget',
        'description' => 'Keep the quantity and size of network requests under the targets set by the provided performance budget. [Learn more](https://developers.google.com/web/tools/lighthouse/audits/budgets).',
        'score' => null,
        'scoreDisplayMode' => 'informative',
        'details' => [
            'type' => 'table',
            'headings' => [],
            'items' => [],
        ],
    ],
    'timing-budget' => [
        'id' => 'timing-budget',
        'title' => 'Timing budget',
        'description' => 'Set a timing budget to help you keep an eye on the performance of your site. Performant sites load fast and respond to user input events quickly. [Learn more](https://developers.google.com/web/tools/lighthouse/audits/budgets).',
        'score' => null,
        'scoreDisplayMode' => 'informative',
        'details' => [
            'type' => 'table',
            'headings' => [
                0 => [
                    'key' => 'label',
                    'itemType' => 'text',
                    'text' => 'Metric',
                ],
                1 => [
                    'key' => 'measurement',
                    'itemType' => 'ms',
                    'text' => 'Measurement',
                ],
                2 => [
                    'key' => 'overBudget',
                    'itemType' => 'ms',
                    'text' => 'Over Budget',
                ],
            ],
            'items' => [
                0 => [
                    'metric' => 'interactive',
                    'label' => 'Time to Interactive',
                    'measurement' => 9900,
                    'overBudget' => 4900,
                ],
            ],
        ],
    ],
];
```
