|
| 1 | +# lighthouse-plugin-crux |
| 2 | + |
| 3 | +> A Lighthouse plugin that displays the field performance of your page. |
| 4 | +> It uses real-world data from Chrome UX Report and Core Web Vitals to estimate the score. |
| 5 | +
|
| 6 | +[An example report for github.com/GoogleChrome/lighthouse](https://googlechrome.github.io/lighthouse/viewer/?gist=cb20232dcc7a8b4e93d63ae3b09ac47e): |
| 7 | + |
| 8 | + |
| 9 | + |
| 10 | +This plugin adds Core Web Vitals values to your Lighthouse report. The CrUX Performance category includes real-user data |
| 11 | +provided by [Chrome UX Report](https://developers.google.com/web/tools/chrome-user-experience-report/). It's similar to |
| 12 | +the field section in [PageSpeed Insights](https://developers.google.com/speed/pagespeed/insights/) but it uses the Chrome |
| 13 | +User Experience Report API instead of the PageSpeed Insights API. This API is faster than the PSI API since it doesn't |
| 14 | +need run a full lighthouse run to give the results. |
| 15 | + |
| 16 | +The scoring algorithm weighs values for Largest Contentful Paint (LCP), First Input Delay (FID), and Cumulative Layout |
| 17 | +Shift (CLS) and picks a **minimum score**. It uses Core Web Vitals assessment that expects all its metrics to pass |
| 18 | +thresholds. For example, https://edition.cnn.com/ has LCP 5.9 s (15), FID 20 ms (100), and CLS 0.02 (100). It has |
| 19 | +`poor` mark in the [Search Console](https://support.google.com/webmasters/answer/9205520), and the score is 15. |
| 20 | +(_Note_: FCP and the origin values do not affect the score, [see the source](./src/plugin.ts)) |
| 21 | + |
| 22 | +Check out the parity between Field & Lab performance on mobile: |
| 23 | + |
| 24 | +<img width="973" alt="Field & lab performance on mobile" src="https://user-images.githubusercontent.com/158189/83353215-31b75b80-a351-11ea-801e-07f5a2b73e51.png"> |
| 25 | + |
| 26 | +And on desktop: |
| 27 | + |
| 28 | +<img width="972" alt="Field & lab performance on desktop" src="https://user-images.githubusercontent.com/158189/83353212-2ebc6b00-a351-11ea-9cf8-6a04a5f0f903.png"> |
| 29 | + |
| 30 | +Sometimes field data is missing because a URL doesn't have enough anonymous traffic. In this case, the lab data is the only available measurement. |
| 31 | + |
| 32 | +## Install |
| 33 | + |
| 34 | +Requires Node.js `12+` and Lighthouse `7+`. |
| 35 | + |
| 36 | +```bash |
| 37 | +$ npm install lighthouse lighthouse-plugin-crux |
| 38 | +``` |
| 39 | + |
| 40 | +## Usage |
| 41 | + |
| 42 | +Use the plugin with [Lighthouse CLI](https://github.com/GoogleChrome/lighthouse): |
| 43 | + |
| 44 | +```bash |
| 45 | +$ npx lighthouse https://www.apple.com/ --plugins=lighthouse-plugin-crux |
| 46 | +``` |
| 47 | + |
| 48 | +Provide your [Chrome User Experience Report token](https://developers.google.com/web/tools/chrome-user-experience-report/api/guides/getting-started) to run more requests (in production) with a custom config: |
| 49 | + |
| 50 | +```bash |
| 51 | +$ npx lighthouse https://www.apple.com/ --config-path=./config.js |
| 52 | +``` |
| 53 | + |
| 54 | +`config.js` |
| 55 | + |
| 56 | +```js |
| 57 | +module.exports = { |
| 58 | + extends: 'lighthouse:default', |
| 59 | + plugins: ['lighthouse-plugin-crux'], |
| 60 | + settings: { |
| 61 | + cruxToken: 'YOUR_REAL_TOKEN', |
| 62 | + }, |
| 63 | +} |
| 64 | +``` |
| 65 | + |
| 66 | +## Credits |
| 67 | + |
| 68 | +Heavily based on the [lighthouse-plugin-field-data](https://github.com/treosh/lighthouse-plugin-field-performance) |
| 69 | + |
| 70 | +[](https://npmjs.org/package/lighthouse-plugin-crux) |
| 71 | +[](./LICENSE) |
0 commit comments