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 autorunGotchas
- 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
How to Profile a Slow Build in GitHub ActionsFind where build time goes in GitHub Actions by enabling your bundler profiler, such as esbuild metafile or w…
How to Enforce a Build-Time Budget in GitHub ActionsFail a GitHub Actions job when the build takes longer than a set number of seconds by timing the build comman…