A static directory site has an unusual shape for performance testing. It might have thousands of pages, but only a handful of templates: the homepage, county pages, city pages, category pages and listing pages. If one template gets slow, every page built from it gets slow at the same time.
That makes Lighthouse CI a good fit. Instead of auditing a live site by hand after something feels sluggish, you run Lighthouse against a sample of built pages on every change and fail the build when a template regresses. This post walks through a setup for a static directory, which pages to sample and which assertions are worth enforcing.
Why test templates instead of pages
Running Lighthouse on every page of a large directory is slow and mostly redundant. Two city pages built from the same template will score almost identically unless one has far more listings than the other.
The useful sample covers each template at its extremes. For a typical directory that means:
- The homepage
- The largest city page, with the most listing cards
- A small city page with only a few listings
- A category page with filters active by default
- A listing page with a map embed
- A listing page with no photo and no map
Six or seven URLs usually cover the variation that matters. Pick them by looking at your build output and finding the pages with the most and fewest items.
A minimal configuration
Lighthouse CI is published on npm as the @lhci/cli package. It can serve a folder of built files itself using the staticDistDir option, so you don't need a separate web server in CI. A configuration file named lighthouserc.json at the project root might look like this:
{
"ci": {
"collect": {
"staticDistDir": "./dist",
"url": [
"http://localhost/index.html",
"http://localhost/springfield/index.html",
"http://localhost/smallville/index.html",
"http://localhost/springfield/plumbers/index.html",
"http://localhost/listing/acme-plumbing/index.html"
],
"numberOfRuns": 3
},
"assert": {
"assertions": {
"categories:performance": ["error", {"minScore": 0.9}],
"categories:accessibility": ["error", {"minScore": 0.95}],
"total-byte-weight": ["warn", {"maxNumericValue": 600000}]
}
}
}
}
Running lhci autorun in CI after your build step collects the reports, checks the assertions and exits with a failure code if any error-level assertion fails. Multiple runs per URL smooth out noise, since a single Lighthouse run on shared CI hardware can vary a fair amount.
Adjust the paths to match how your generator names output files. If your pages live at folder paths with an index.html inside, list them that way.
Assertions that matter for a directory
Category scores are a blunt instrument. They're fine as a backstop, but the specific audits tell you more about what broke.
Total byte weight catches the most common directory regression: someone adds a large hero image, a font family with six weights or a JavaScript library for the filters. A warning threshold on the city page template is a simple guard.
Largest Contentful Paint matters on city pages, where the first listing card or heading is usually the largest element. If a template starts loading a big map above the listings, this audit will show it.
Cumulative Layout Shift catches cards that jump when images load. Directory cards with photos are a frequent source, especially when width and height attributes are missing.
Accessibility audits are worth enforcing too. Color contrast on filter chips, missing labels on search inputs and links with no text show up often on directory templates.
One caveat on interactivity: Interaction to Next Paint is a field metric measured from real users, and a standard Lighthouse page load can't measure it directly. Total Blocking Time is the lab audit that tends to move with it, so watch TBT on pages with heavy filter scripts.
Handling maps and third-party embeds
Maps are often the heaviest thing on a directory page. A full interactive map loaded on page load can add a lot of JavaScript and network requests.
A common approach is to show a static preview or a button that says "Show map" and load the interactive map only on click. Lighthouse CI makes the benefit visible: compare a listing page with an eager map against the same page with a click-to-load map, and the difference in blocking time and byte weight is usually clear.
If you keep a map loaded eagerly on some template, give that URL looser thresholds in a separate assertion block rather than relaxing the rules for every page.
Fitting it into the build
Run the build, then Lighthouse CI, in the same job. On static hosts that build from Git, you can also run it on pull requests so a slow template never reaches production.
Store the reports. Lighthouse CI can upload to temporary public storage or to a self-hosted server, and either lets you compare runs over time. Even without that, keeping the HTML reports as build artifacts helps when you need to see what changed.
If you are still choosing where those builds should live, this guide on choosing where to host your first static directory site compares the usual options.
Questions about Lighthouse CI for directories
Do I need a running server for Lighthouse CI?
Not for a static site. The staticDistDir option tells Lighthouse CI to serve the build folder itself. A server is only needed if your pages depend on server-side rendering at request time.
Why do my scores vary between runs?
Shared CI machines have variable load. Running each URL several times and letting Lighthouse CI use the median reduces noise. Set thresholds with a little headroom rather than at the exact score you saw once.
Should I test with mobile or desktop settings?
Mobile is the default and is the better fit for local directories, since most local searches happen on phones. Add a desktop run only if you have a desktop-specific layout worth guarding.
For more on testing and measuring directory sites, there's a collection of notes on measurement for directory builders. If you'd rather skip writing the generator, 1 Click Directory Builder turns a Google Maps export into a complete static directory site you can put under the same checks.
Top comments (0)