Files
ipal-kit/docs/agent/skills/iapl-performance/SKILL.md
T

4.5 KiB
Raw Blame History

name, description
name description
iapl-performance Makes and keeps an IAPL site fast — page loading (LCP image, fonts, nothing render-blocking, static rendering), elements (lazy below the fold, reserved space, click-to-load embeds), animations (transform/opacity, reduced motion, no scroll handlers), resources (only the JS a page uses, compression, no third-party request before consent), images (AVIF/WebP, sizes, upload limits) and the server (queries per render, depth, select, caching). Measures the built site, runs the doctor's performance group, and adds the budget gate that fails when a change makes the site slower. Use when building pages or blocks, before handing over, after an IAPL upgrade, and whenever "slow", PageSpeed, Lighthouse, Core Web Vitals, LCP, CLS or INP come up.

iapl-performance

The handbook is node_modules/@intecion/ipal-kit/docs/performance.md: what the plugin does for you, what the project must do, how to measure, how to read the findings. This skill is the order of work.

1. Check what the plugin cannot do for you (code)

pnpm exec iapl-doctor --only performance                 # images config, fonts, render-blocking, embeds, animations, budget test
bash .agents/skills/iapl-audit/scripts/audit.sh --quick  # <img>/<video> outside Media, priority outside the hero, YouTube iframe, h-screen

Fix every warning — each names the file, the fix and the doc. The rules that matter most:

Area Do Never
LCP image <Media priority> on the first image of the page — one per page; a header logo gets eager priority on many images; a lazy hero; the hero as a CSS background
other images <Media sizes={MEDIA_SIZES.third}> — the width on screen; lazy by default no sizes; a plain <img>
fonts next/font (self-hosted), ≤ 2 families, variable, display: 'swap' a <link> to Google Fonts; display: 'block'
scripts the plugin's Analytics / ConsentScript; next/script for anything else a <script src> without async in the layout
embeds <YouTubeEmbed>; a map or widget behind a click (a picture + a button) an <iframe> that loads with the page
animations transform / opacity only; the token durations (duration-fast) or motion-reduce: animating height, top, margin; transition-all; a scroll listener (use IntersectionObserver)
client code small 'use client' leaves; server components by default a whole section 'use client'
server the plugin's cached helpers (lib/content), depth as low as the page needs, select for one field findGlobal without cache(); depth: 2 "to be safe"; a query per list item

2. Measure the built site

pnpm build && pnpm start                     # dev numbers mean nothing
pnpm exec iapl-doctor --url http://localhost:3000 --only perf-live      # compression, blocking scripts, preloads, lazy hero, HTML size
pnpm exec iapl-doctor --deep --only perf-images                         # stored images over 1.5 MB / 2560 px

Lab numbers per page (phone on Slow 4G with a 4× slower CPU, and desktop): copy resources/perf-lab.mjs and resources/performance.spec.template.ts (→ e2e/performance.spec.ts), list one page of each template, run pnpm test:e2e performance, then set each budget to what you measured plus ~20 %. From then on the test fails when a change makes a page slower. PageSpeed Insights on the deployed site shows the field data (real visitors).

3. Read the result

  • LCP > 2.5 s on the phone: the LCP element is named in the measurement (lcpElement). An image → priority, sizes, a smaller upload; text → a font that arrives late (fewer preloaded files).
  • CLS > 0.1: an image without dimensions (use Media), content that arrives after hydration (the lazy 404 — createNotFoundPage({ load, placeholder })), a font swap (next/font sets fallback metrics).
  • TBT / INP: long tasks — a big client component, a scroll handler, a third-party widget at start.
  • JS bytes: what the page ships; import client components from @intecion/ipal-kit/client freely — since 1.18.0 a page carries only the ones it renders.
  • Queries per render (the reference gate counts them): over 30 for an ordinary page → a missing cache(), a depth too high, or a loop of findByID.

4. Before "done"

iapl-doctor --only performance without warnings (or each one silenced with a reason in iapl-doctor.json), the budget test green, and the numbers in AGENTS.md → "Project decisions" when the client accepted an exception (a heavy font, a third-party widget).