Measuring Page Speed with Lighthouse
Tags: performance, webdev, programming, tutorial
Published: 2023-01-10 21:49:31

Photo by <a href="https://unsplash.com/@paulius005?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText">Paulius Dragunas</a> on <a href="https://unsplash.com/images/things/lighthouse?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText">Unsplash</a>
  

Page speed matters more than you think. According to [research by Google](https://www.thinkwithgoogle.com/marketing-strategies/app-and-mobile/mobile-page-speed-new-industry-benchmarks/), the probability of users staying on your site plummets as loading speed slows down. A site that loads in 10 seconds increases the bounce rate by a whopping 123%. In other words, speed equals revenue.


![Graph showing bounce rates for page load times. The values shown are 1 to 3 seconds = 32% bounce rate, 1 to 5 seconds = 90%, 1 to 6 seconds 106%, and 1 to 10 seconds 123%.](https://raw.githubusercontent.com/tomfern/blog-assets/master/images/12ea625382d312655c16e7323d08d14af46381763659380b9b5a34983b2ca921.jpg)
Source: [find out how you stack up to new industry benchmarks for mobile page speed](https://www.thinkwithgoogle.com/marketing-strategies/app-and-mobile/mobile-page-speed-new-industry-benchmarks/).

How can we ensure that our pages are loading at top speed? The answer is to measure them regularly with Lighthouse and CI/CD.

## Measuring page speed with Lighthouse

[Lighthouse](https://developer.chrome.com/docs/lighthouse/overview/) is a page speed benchmark tool created by Google. It runs a battery of tests against your website and produces a report with detailed advice to improve performance.


![The Lighthouse HTML report. Includes scores for Performance, Accessibility, PWA, and Best practices. It also shows a sequence of how the webpage is rendered over time.](https://raw.githubusercontent.com/tomfern/blog-assets/master/images/cf359bafc22b38ec1f37d80df83c814be675fc59fe14a9c5d10db735add800bf.jpg)
Lighthouse running inside Google Chrome.

⚠️ You might be surprised at the low scores Lighthouse presents. This is because the tool simulates mid-tier mobile devices on a 4G connection.

While Lighthouse's primary focus is performance, it can assess other things like:

- **Accessibility**: suggests opportunities to make the content more accessible. This covers ensuring that the page is optimized for screen readers, all elements have labels, or the site is browsable with the keyboard.
- **Best practices**: checks for various sane practices that improve speed and security.
- **SEO**: performs various checks to ensure that the page is SEO-optimized.
- **PWA**: ensures the page passes progressive web application tests, which improves user experience on mobile devices.

### 4 ways of running Lighthouse

Lighthouse is an open-source project that you can run in different ways:
1. Since it is included in Google Chrome, you can run it directly from the browser. Click on **More tools** > **Developer Tools** and open the Lighthouse tab.
2. If you have Node installed, you can run `npm install -g lighthouse` and run the tool in the command line like this: `lighthouse https://semaphoreci.com`
3. You can include it in your code as a Node package.
4. And finally, Lighthouse has a [CI version](https://github.com/GoogleChrome/lighthouse-ci) you can run in your [continuous integration](https://semaphoreci.com/continuous-integration). We’ll use this method to schedule periodical benchmarks.

If you want to learn how to run Lighthouse with CI/CD to get a report on every change, check out this tutorial: [Setting up Lighthouse CI](https://semaphoreci.com/blog/lighthouse-page-speed#setting-up-lighthouse-ci)

### Setting up a dashboard

The Lighthouse CI project includes an [optional dashboard](https://github.com/GoogleChrome/lighthouse-ci/blob/main/docs/server.md) that lets you browse historical data and find trends.


![The Lighthouse Server Dashboard. It shows a graph of the page score over time and entries for the last 5 runs.](https://raw.githubusercontent.com/tomfern/blog-assets/master/images/eb78ab83e91917628693408da1542901efc75dbdc10ee7c3e8e37ae20f093dac.jpg)
Lighthouse CI dashboard.

Installing the dashboard requires a separate server and database. You’ll need a dedicated machine and persistent storage to save historical data.

The downside of this approach is obvious — you need to manage yet another server. But it may be worth doing if you have a lot of sites to analyze.

## Time is money

Users are drawn to fast and responsive websites. The problem is that measuring page speed reliably is challenging since you cannot assume that everyone is on a fast connection and uses a top-tier device. With Lighthouse in your CI/CD pipeline, you can get results closer to real-life conditions and insights to help you continually improve.

Thanks for reading!