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

6.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); what grows in the database and on disk over the years (logs and their retention, form submissions, versions, KV, unused media, the image cache). 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, INP, a growing database or disk 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

These are errors since 1.18.0 (iapl-doctor fails). Fix each — it names the file, the fix and the doc. When the client accepts one (a brand font, a map that is the page's content), lower it with a reason in iapl-doctor.json ("perf-fonts": { "severity": "warning", "reason": "…" }) or silence it ("off": true, optionally until), and record it in AGENTS.md → Project decisions. 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
layout shift content that arrives late keeps its space: the lazy 404's placeholder (its content's height), the Turnstile widget's 73 px (kept by the plugin) an empty box a widget or a server action fills later
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', the heading font preload: false 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; forms through RenderForm / BuilderForm from /client (their code loads only where a form is shown) a whole section 'use client'; importing /client/eager without a reason
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 e2e/performance.spec, 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. What grows (performance.md §6)

pnpm exec iapl-doctor --deep --only growth   # counts and sizes per collection, oldest records, versions, expired KV, unused media, disk
  • Logs purge themselves (consent log 1095 days, statistics 90). Form submissions are kept unless iapl({ forms: { submissionRetentionDays } }) — ask the client (personal data) and record it in AGENTS.md.
  • Versions: where you turn them on, versions: { maxPerDoc: 20 } (globals max); never 0.
  • Unused media: iapl({ unusedMedia: true }) (then pnpm generate:importmap) shows them above the Media list with a link to Payload's filtered list; the editor deletes them there. The plugin never deletes media or submissions by itself.
  • MongoDB: the consent log and statistics are deleted by TTL indexes at their retention (ttlIndex: false turns that off).
  • Coolify: no persistent volume on .next (the image cache starts empty on each deploy); database backups on the MongoDB resource.
  • Thresholds of the findings: iapl-doctor.json → growth.

5. Before "done"

iapl-doctor --only performance without errors (each exception lowered or 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).