image-pulse

Pulse · web performance

image-pulse

Find oversized, unoptimised and wrongly formatted images in your built site, before they slow down your Largest Contentful Paint.

npm i -D @mrlouiswright/image-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

  • Bytesper-image budget (--max-kb, default 250 kB; above 1 MB is high severity).
  • Dimensionsintrinsic width vs displayed width (from width or sizes), allowing 2.5× for high-DPI screens; aspect-ratio mismatches between attributes and the file.
  • FormatsJPEG/PNG without an AVIF or WebP alternative (<picture><source type> or srcset), opaque PNG photos, animated GIFs, baseline JPEGs, SVGs carrying editor metadata.
  • Responsive markuplarge images without srcset, w-descriptor srcsets without sizes, <img> without width/height (layout shift).
  • Local and fastdimension parsing for PNG, JPEG, GIF, WebP (VP8/VP8L/VP8X), AVIF/HEIF and SVG with no native modules; external images get markup checks only.

Quick usage

CLI

npx image-pulse dist
npx image-pulse public --max-kb 150 --fail-on medium
npx image-pulse _site --format sarif > images.sarif

API

import { check, imageInfo } from "image-pulse";
imageInfo(readFileSync("hero.jpg")); // { format: "jpeg", width: 1600, height: 900, progressive: true }
const report = check("dist", { maxBytes: 200 * 1024 });

Every option is documented in the image-pulse docs.

CI / GitHub Action

permissions:
  contents: read
  security-events: write   # only needed for the SARIF upload
jobs:
  image-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/image-pulse@v1
        with:
          path: dist
          fail-on: high
          sarif: image-pulse.sarif
      - uses: github/codeql-action/upload-sarif@v3
        if: always()
        with: { sarif_file: image-pulse.sarif }