Skip to content
Latchkey

How to Cache a Browser and Dependencies to Speed Up the Perf Job in GitHub Actions

A performance job spends real time reinstalling packages and downloading Chrome; caching both removes that overhead from each run.

Use the cache input of setup-node for dependencies, and cache the Puppeteer or Chrome download directory so Lighthouse does not re-fetch a browser every run.

Steps

  • Enable the built-in npm cache on setup-node.
  • Cache the Puppeteer cache dir keyed on the lockfile.
  • Run the perf tool with the cached browser in place.

Workflow

.github/workflows/ci.yml
jobs:
  perf:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: 20
          cache: npm
      - uses: actions/cache@v4
        with:
          path: ~/.cache/puppeteer
          key: chrome-${{ hashFiles('package-lock.json') }}
      - run: npm ci
      - run: npx lhci autorun

Gotchas

  • Pin the browser version so a cached binary stays compatible with the tool.
  • Cache only what you can rebuild; never cache the measured artifact you are profiling.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →