lazy-pulse

Pulse · web performance

lazy-pulse

Lazy-load what is below the fold, never the LCP image: a static lazy-loading audit for your built site.

npm i -D @mrlouiswright/lazy-pulse

Published to GitHub Packages: add @mrlouiswright:registry=https://npm.pkg.github.com to .npmrc first (installing needs a token with read:packages).

What it checks

  • LCP candidatethe image with fetchpriority="high", else a preloaded image, else the first content image (icons, logos in nav/header, tracking pixels and <noscript> are skipped).
  • LCP mistakesloading="lazy" (high), lazy-loaded by JavaScript via data-src (high), fetchpriority="low" (medium), a <link rel=preload as=image> for an image that is lazy (high), and no fetchpriority at all (info).
  • Below the foldimages and iframes without loading="lazy" after the first foldImages content images (default 1 after the LCP image); iframes (video, maps, widgets) are always expected to be lazy unless allowlisted.
  • Above the foldcontent images near the top that are lazy (low).
  • Hygienelazy images without width/height or aspect-ratio (layout shift), and JS lazy-load libraries where native lazy loading would do.

Quick usage

CLI

npx lazy-pulse dist
npx lazy-pulse _site --fold-images 2
npx lazy-pulse public --fail-on medium -f sarif > lazy.sarif

API

import { check, parseHtml, mediaOf, lcpCandidate } from "lazy-pulse";
const doc = parseHtml(html);
lcpCandidate(doc, mediaOf(doc))?.el.attrs.src;
check("dist", { foldImages: 2 }).findings;

Every option is documented in the lazy-pulse docs.

CI / GitHub Action

permissions:
  contents: read
  security-events: write   # only needed for the SARIF upload
jobs:
  lazy-pulse:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
        with: { persist-credentials: false }
      - run: npm ci && npm run build   # produce the static site first
      - uses: MrLouisWright/lazy-pulse@v1
        with:
          path: dist
          fail-on: high
          sarif: lazy-pulse.sarif
      - uses: github/codeql-action/upload-sarif@v3
        if: always()
        with: { sarif_file: lazy-pulse.sarif }