Docs: performance.md, the iapl-performance skill, AGENT.md 6.11b, doctor.md, audit, api.md, the measurements and the audit

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
Radosław Smoliński
2026-12-01 13:51:43 +01:00
co-authored by Claude Opus 5.5
parent 801b897ea0
commit c6c5dfbcbf
16 changed files with 1367 additions and 18 deletions
+1
View File
@@ -50,6 +50,7 @@ API details — one file per module:
| Rich text, table of contents | [richtext.md](./richtext.md) |
| Headers, CSP, 2FA | [security.md](./security.md) |
| SEO, metadata, sitemap, JSON-LD, llms.txt | [seo.md](./seo.md) |
| Speed: what the plugin does, what the project does, budgets, measuring, the doctor's performance group | [performance.md](./performance.md) |
| Stats in the admin panel (no cookies; visitor history with consent) | [stats.md](./stats.md) |
| Auto-slug | [slug.md](./slug.md) |
| Light / dark theme, switcher | [theme.md](./theme.md) |
+20 -10
View File
@@ -1041,22 +1041,29 @@ Example `styles.css`: [section-code.md](./skills/iapl-block/resources/section-co
125 % and 150 % zoom at 1366 (common on Windows). No horizontal scroll, no clipped text,
the menu works, the hero CTA is visible.
### 6.11b Speed (Core Web Vitals)
### 6.11b Speed (Core Web Vitals) — the handbook is [performance.md](../performance.md), the skill `iapl-performance`
| What | How | Forbidden |
|---|---|---|
| LCP image (the first visible one, usually the hero) | `<Media priority>` — exactly one per page | `priority` on many images, the hero as a CSS `background-image` |
| every other image | `<Media sizes={MEDIA_SIZES.third}>` — `sizes` = the width on screen | no `sizes` (downloads the full width), `<img>` |
| LCP image (the first visible one, usually the hero) | `<Media priority>` — exactly one per page (preload + `fetchpriority="high"`) | `priority` on many images, the hero as a CSS `background-image`, a lazy hero |
| above the fold, not the LCP (header logo) | `<Media eager>` — loads at once, no high priority, no preload | `priority` on the logo (it competes with the hero) |
| every other image | `<Media sizes={MEDIA_SIZES.third}>` — `sizes` = the width on screen; lazy by default | no `sizes` (downloads the full width), `<img>` |
| placeholder | `buildMediaPlaceholderHook` + a field in Media (blur + color) | empty boxes that "jump in" while loading |
| uploads | `buildOptimizeUploadHook` (stops images over 1.5 MB / 2560 px, converts on request); `iapl-doctor --deep` counts stored images over the limits | 8 MB phone photos in the library |
| background video | `videoMode="background"`, MP4 H.264 ≤ 20 MB, no sound, with a poster | a video as the hero without a poster, `autoplay` with sound |
| video with content | `videoMode="player"` (loads after a click) | `preload="auto"` |
| YouTube | `<YouTubeEmbed>` from `/client` (the iframe only after a click) | a bare `<iframe src="youtube.com/embed…">` |
| next.config | `images: { ...buildImagesConfig() }` (AVIF/WebP, R2) | no `remotePatterns` → images from R2 without optimization |
| fonts | `next/font`, max 2 families × 2–3 weights, `subsets: ['latin', 'latin-ext']` (PL), `display: 'swap'` | a `<link>` to Google Fonts, 6 weights "just in case" |
| third-party scripts | `Analytics` (via `SiteProviders`, `analytics={{ defer: true }}`) / `ConsentScript` from the plugin | chat/map widgets loaded at start |
| client components | small, interaction only (§6.9) | a whole section `'use client'` |
| YouTube, maps, widgets | `<YouTubeEmbed>` from `/client` (the iframe only after a click); a map behind a click (a picture + a button) | a bare `<iframe>` that loads with the page |
| next.config | `images: buildImagesConfig()` (AVIF/WebP, R2, 31-day cache) | no `remotePatterns` → images from R2 without optimization |
| fonts | `next/font`, max 2 families, variable, `subsets: ['latin', 'latin-ext']` (PL), `display: 'swap'` | a `<link>` to Google Fonts, `display: 'block'`, 6 weights "just in case" |
| third-party scripts | `Analytics` (via `SiteProviders`, `analytics={{ defer: true }}`) / `ConsentScript` from the plugin; `next/script` for anything else | `<script src>` without `async` in the layout, chat/map widgets loaded at start |
| animations | `transform` / `opacity` only, the token durations (`duration-fast`, reduced motion built in) or `motion-reduce:`; IntersectionObserver for "is it on screen" | animating `height` / `top` / `margin`, `transition-all`, a `scroll` listener doing work per event |
| client components | small, interaction only (§6.9); import from `@intecion/ipal-kit/client` freely — a page ships only what it renders (1.18.0) | a whole section `'use client'` |
| data | the cached helpers of `lib/content` (`getSettings`, `resolveRoute`, `getSiteShell`…), `depth` as low as the page needs, `select` when you need one field, `cache()` around your own getters | `findGlobal` in a component without `cache()`, `depth: 2` "to be safe", a query per list item |
| budgets | `e2e/performance.spec.ts` from the `iapl-performance` skill (`perfBudgets()` from `/doctor`): fails when a page gets slower | "it felt fast on my machine" |
Target on the built site (mobile, Lighthouse/PageSpeed): LCP < 2.5 s, CLS < 0.1, INP < 200 ms.
Checks: `iapl-audit` (img/video outside Media, many `priority`, `h-screen`, fixed widths,
Target on the built site (mobile, Lighthouse/PageSpeed): LCP < 2.5 s, CLS < 0.1, INP < 200 ms — the plugin's default
budgets (`PERF_BUDGETS`). Checks: `iapl-doctor --only performance` (images config, fonts, render-blocking, embeds,
animations, a budget test; `--url`: compression, blocking scripts, preloads, a lazy first image, HTML size; `--deep`:
stored images over the limits), `iapl-audit` (img/video outside Media, many `priority`, `h-screen`, fixed widths,
YouTube `<iframe>`) and `iapl-seo-check` (images without dimensions, LCP image without priority).
### 6.12 Exports and imports
@@ -1554,6 +1561,7 @@ block library — [doctor.md](../doctor.md)):
bash .agents/skills/iapl-audit/scripts/audit.sh
pnpm exec iapl-doctor # + --deep --url http://localhost:3000 on the built site
node .agents/skills/iapl-seo-check/scripts/seo-check.mjs http://localhost:3000
pnpm test:e2e performance # the budget gate (iapl-performance) on the built site
pnpm generate:types && pnpm tsc --noEmit
pnpm build # --webpack in the script; locally, not only dev
# hardcoding and the field zoo in blocks
@@ -1614,6 +1622,7 @@ Anything that needs a developer → move it to the panel.
| Rich text | [richtext.md](../richtext.md) |
| Headers, CSP, 2FA, panel path | [security.md](../security.md) |
| SEO, metadata, sitemap, JSON-LD, llms.txt | [seo.md](../seo.md) |
| Speed: what the plugin does, what the project does, budgets, measuring, the doctor's performance group | [performance.md](../performance.md) |
| Auto-slug | [slug.md](../slug.md) |
| Media: collection, file names, optimization, placeholders | [media.md](../media.md) |
| Image lightbox (enlarge, galleries, rich text images) | [lightbox.md](../lightbox.md) |
@@ -1695,6 +1704,7 @@ the task matches — manually: `/<name>`.
| `iapl-debug` | anything does not work — procedure + a symptom → cause → fix table |
| `iapl-audit` | before every "done" — the §0b set + the §11 checks + panel (§6.5a) + hardcoding in JSX + tsc + build |
| `iapl-seo-check` | the running site through the eyes of Googlebot and AI agents (head, canonical, hreflang, sitemap, 404, JSON-LD, llms, Markdown, MCP) |
| `iapl-performance` | speed: the doctor's performance group, measuring the built site (phone and desktop), the budget gate `e2e/performance.spec.ts` (`resources/`), reading LCP / CLS / INP / bytes / queries — when building pages or blocks, before handing over, whenever "slow" or PageSpeed comes up |
| `iapl-consent-check` | browser: no tracking pixels or cookies before consent; the Google tag may load before consent only in Consent Mode `advanced` (all signals `denied`) — a client who wants zero requests gets `consentMode: 'basic'` |
| `iapl-doctor` | the whole site against the team standard in one command (`pnpm exec iapl-doctor`): versions, Node 22, layout, database names, env, headers, CSP, 2FA, cookie scanner, adminMeta, AGENTS.md, skills, seeds, block library, pnpm audit; `--url` / `--deep` for the running site and the database; `--strict` in the CI of a new site |
| `iapl-plugin-gap` | IAPL has a bug or is missing a feature — report to the owner, wait for the decision; a marked workaround only after approval |
+7
View File
@@ -42,6 +42,13 @@ classes (warnings), `styles.css` without `@intecion/ipal-kit/tokens.css` (warnin
next/font in `--font-body` with the preset (warning), and with `src/design/tokens.ts`: no `DESIGN.md` (warning) and
`iapl-tokens --check` — a stale `src/design/tokens.css` or a WCAG AA contrast failure is an error.
## Speed (AGENT.md §6.11b, docs/performance.md)
The full run (not `--quick`) lists the doctor's `performance` group as warnings: `next.config` without
`buildImagesConfig()`, fonts from Google or with `display: 'block'`, more than two families, a blocking `<script src>`
or a remote stylesheet, an `<iframe>` that loads with the page, transitions of layout properties, `transition-all`,
`scroll` listeners, animations with nothing for reduced motion. The `iapl-performance` skill measures the built site and
adds the budget test.
## iapl-audit and iapl-doctor
`iapl-audit` checks the **code** inside the edit loop (and tsc + build). `pnpm exec iapl-doctor` checks the **site**
against the team standard: it runs this script (`--quick`) from the installed package, reports its findings under its
@@ -362,6 +362,14 @@ if [ -n "$UI" ]; then
done
fi
# --- Speed (§6.11b, performance.md) — the doctor's performance group: images config, fonts, render-blocking,
# embeds, animations, a budget test. Full mode only: the doctor itself runs this audit with --quick.
if [ "$QUICK" -eq 0 ] && [ -x node_modules/.bin/iapl-doctor ]; then
PERF=$(node_modules/.bin/iapl-doctor --only performance --offline --json 2>/dev/null \
| node -e 'let s="";process.stdin.on("data",(d)=>(s+=d)).on("end",()=>{try{for(const f of JSON.parse(s).findings){if(!f.silenced&&f.severity!=="info"){console.log(`${f.file??"(site)"} [${f.rule}] ${f.message}`)}}}catch{}})')
report WARNING "speed (iapl-doctor --only performance)" "§6.11b / performance.md — each line names the rule; iapl-performance skill" "$PERF"
fi
# --- Compile & build ---
if [ "$QUICK" -eq 0 ]; then
echo
@@ -0,0 +1,54 @@
---
name: iapl-performance
description: 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)
```bash
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
```bash
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).
@@ -0,0 +1,165 @@
/**
* Lab measurements of one page in Chromium (Playwright + the DevTools protocol) — used by `pnpm perf:measure`
* (scripts/perf-measure.mjs, numbers for docs/performance.md) and by the budget gate (e2e/performance.spec.ts).
*
* Profiles follow Lighthouse's defaults so the numbers compare with PageSpeed Insights' lab data:
* - mobile: 412×823 at DPR 1.75, "Slow 4G" (150 ms RTT, 1.6 Mbit/s down, 750 kbit/s up), CPU 4× slower;
* - desktop: 1350×940, 40 ms RTT, 10 Mbit/s, CPU 1×.
* Every run is a fresh browser context (empty HTTP cache, no cookies): a first visit, the worst ordinary case.
*
* What is measured (all from the browser itself, web.dev/articles/vitals):
* ttfb, fcp, lcp (+ the LCP element: tag, src, loading, fetchpriority), cls (session windows, as web-vitals does),
* tbt (sum of long-task time over 50 ms between FCP and the end of the run: the lab stand-in for INP),
* inp (the longest Event Timing entry of one scripted interaction: a click on the page's first visible button),
* scriptMs (CDP Performance.ScriptDuration: parse, compile, run and hydrate), requests, bytes per type
* (transfer size, compressed), renderBlocking (resource timing renderBlockingStatus), thirdParty (requests to
* another origin before any consent is given).
*/
import { chromium } from '@playwright/test'
export const PROFILES = {
desktop: { cpu: 1, network: { downloadThroughput: (10 * 1024 * 1024) / 8, latency: 40, uploadThroughput: (10 * 1024 * 1024) / 8 }, viewport: { deviceScaleFactor: 1, height: 940, isMobile: false, width: 1350 } },
mobile: { cpu: 4, network: { downloadThroughput: (1.6 * 1024 * 1024) / 8, latency: 150, uploadThroughput: (750 * 1024) / 8 }, viewport: { deviceScaleFactor: 1.75, hasTouch: true, height: 823, isMobile: true, width: 412 } },
}
const OBSERVERS = `(() => {
const v = (window.__perf = { cls: 0, events: [], lcp: null, longTasks: [] })
let win = 0, winStart = 0, winLast = 0
new PerformanceObserver((l) => { for (const e of l.getEntries()) {
const el = e.element
v.lcp = { at: e.startTime, size: e.size, tag: el ? el.tagName.toLowerCase() : null, src: e.url || null,
loading: el && el.getAttribute ? el.getAttribute('loading') : null,
fetchpriority: el && el.getAttribute ? el.getAttribute('fetchpriority') : null }
} }).observe({ buffered: true, type: 'largest-contentful-paint' })
new PerformanceObserver((l) => { for (const e of l.getEntries()) {
if (e.hadRecentInput) continue
if (win && e.startTime - winLast < 1000 && e.startTime - winStart < 5000) { win += e.value } else { win = e.value; winStart = e.startTime }
winLast = e.startTime
v.cls = Math.max(v.cls, win)
} }).observe({ buffered: true, type: 'layout-shift' })
new PerformanceObserver((l) => { for (const e of l.getEntries()) v.longTasks.push([e.startTime, e.duration]) }).observe({ buffered: true, type: 'longtask' })
new PerformanceObserver((l) => { for (const e of l.getEntries()) v.events.push({ d: e.duration, n: e.name }) }).observe({ buffered: true, durationThreshold: 16, type: 'event' })
})()`
/**
* @typedef {{ bytes: { css: number, font: number, html: number, image: number, js: number, other: number }, cls: number,
* fcp: null | number, inp: null | number, interaction: null | string, lcp: null | number,
* lcpElement: null | { fetchpriority: null | string, loading: null | string, src: null | string, tag: null | string },
* load: null | number, profile: string, renderBlocking: string[], requests: number, runs?: number, scriptMs: null | number,
* status: null | number, tbt: null | number, thirdParty: string[], ttfb: null | number, url: string }} PageMeasurement
*/
const typeOf = (resourceType, mime = '') => {
if (resourceType === 'Document') {return 'html'}
if (resourceType === 'Script') {return 'js'}
if (resourceType === 'Stylesheet') {return 'css'}
if (resourceType === 'Font') {return 'font'}
if (resourceType === 'Image' || mime.startsWith('image/')) {return 'image'}
return 'other'
}
/**
* @param {import('@playwright/test').Browser} browser
* @param {string} url
* @param {'mobile'|'desktop'} profileName
* @param {{ interact?: boolean, settleMs?: number }} [options]
* @returns {Promise<PageMeasurement>}
*/
export async function measurePage(browser, url, profileName, options = {}) {
const profile = PROFILES[profileName]
const context = await browser.newContext({ ...profile.viewport, viewport: { height: profile.viewport.height, width: profile.viewport.width } })
const page = await context.newPage()
const cdp = await context.newCDPSession(page)
await cdp.send('Network.enable')
await cdp.send('Network.setCacheDisabled', { cacheDisabled: true })
await cdp.send('Network.emulateNetworkConditions', { offline: false, ...profile.network })
await cdp.send('Emulation.setCPUThrottlingRate', { rate: profile.cpu })
await cdp.send('Performance.enable')
await page.addInitScript(OBSERVERS)
const origin = new URL(url).origin
const requests = new Map()
cdp.on('Network.requestWillBeSent', (e) => { if (!e.request.url.startsWith('data:')) {requests.set(e.requestId, { bytes: 0, type: typeOf(e.type), url: e.request.url })} })
cdp.on('Network.responseReceived', (e) => { const r = requests.get(e.requestId); if (r) {r.type = typeOf(e.type, e.response.mimeType); r.status = e.response.status} })
cdp.on('Network.loadingFinished', (e) => { const r = requests.get(e.requestId); if (r) {r.bytes = e.encodedDataLength} })
const response = await page.goto(url, { waitUntil: 'load' })
await page.waitForLoadState('networkidle').catch(() => {})
await page.waitForTimeout(options.settleMs ?? 1000)
let interaction = null
if (options.interact !== false) {
// INP stand-in: one click on the first visible button (menu toggle, cookie settings, theme): a real handler runs
const button = page.locator('button:visible').first()
if (await button.count()) {
interaction = (await button.getAttribute('aria-label')) ?? (await button.innerText()).slice(0, 40)
await button.click({ timeout: 5000 }).catch(() => { interaction = null })
await page.waitForTimeout(500)
}
}
const nav = await page.evaluate(() => {
const n = performance.getEntriesByType('navigation')[0]
const fcp = performance.getEntriesByName('first-contentful-paint')[0]
const blocking = performance.getEntriesByType('resource').filter((r) => r.renderBlockingStatus === 'blocking').map((r) => r.name)
return { blocking, domContentLoaded: n.domContentLoadedEventEnd, fcp: fcp ? fcp.startTime : null, load: n.loadEventEnd, ttfb: n.responseStart }
})
const vitals = await page.evaluate(() => window.__perf)
const { metrics } = await cdp.send('Performance.getMetrics')
const metric = (name) => metrics.find((m) => m.name === name)?.value ?? 0
await context.close()
const list = [...requests.values()]
const bytes = { css: 0, font: 0, html: 0, image: 0, js: 0, other: 0 }
for (const r of list) {bytes[r.type] += r.bytes}
const fcp = nav.fcp ?? 0
const tbt = vitals.longTasks.filter(([start]) => start >= fcp).reduce((sum, [, d]) => sum + Math.max(0, d - 50), 0)
const round = (n) => (n == null ? null : Math.round(n))
return {
bytes: Object.fromEntries(Object.entries(bytes).map(([k, b]) => [k, Math.round(b)])),
cls: Math.round(vitals.cls * 1000) / 1000,
fcp: round(nav.fcp),
inp: vitals.events.length ? round(Math.max(...vitals.events.map((e) => e.d))) : interaction ? 0 : null,
interaction,
lcp: round(vitals.lcp?.at),
lcpElement: vitals.lcp ? { fetchpriority: vitals.lcp.fetchpriority, loading: vitals.lcp.loading, src: vitals.lcp.src ? vitals.lcp.src.replace(origin, '') : null, tag: vitals.lcp.tag } : null,
load: round(nav.load),
profile: profileName,
renderBlocking: nav.blocking.map((u) => u.replace(origin, '')),
requests: list.length,
scriptMs: round(metric('ScriptDuration') * 1000),
status: response?.status() ?? null,
tbt: round(tbt),
thirdParty: [...new Set(list.filter((r) => !r.url.startsWith(origin)).map((r) => new URL(r.url).origin))],
ttfb: round(nav.ttfb),
url: url.replace(origin, ''),
}
}
export const median = (values) => {
const sorted = values.filter((v) => typeof v === 'number').sort((a, b) => a - b)
if (!sorted.length) {return null}
const mid = Math.floor(sorted.length / 2)
return sorted.length % 2 ? sorted[mid] : Math.round(((sorted[mid - 1] + sorted[mid]) / 2) * 1000) / 1000
}
/**
* The median of `runs` measurements for every number; the rest from the last run.
* @param {import('@playwright/test').Browser} browser
* @param {string} url
* @param {'mobile'|'desktop'} profileName
* @param {number} [runs]
* @param {{ interact?: boolean, settleMs?: number }} [options]
* @returns {Promise<PageMeasurement>}
*/
export async function measureMedian(browser, url, profileName, runs = 3, options = {}) {
const all = []
for (let i = 0; i < runs; i++) {all.push(await measurePage(browser, url, profileName, options))}
const last = all.at(-1)
const out = { ...last, runs }
for (const key of ['cls', 'fcp', 'inp', 'lcp', 'load', 'requests', 'scriptMs', 'tbt', 'ttfb']) {out[key] = median(all.map((r) => r[key]))}
out.bytes = Object.fromEntries(Object.keys(last.bytes).map((k) => [k, median(all.map((r) => r.bytes[k]))]))
return out
}
export const launch = () => chromium.launch()
@@ -0,0 +1,47 @@
// e2e/performance.spec.ts — the project's performance budget gate (iapl-performance skill, docs/performance.md).
// Copy this file and perf-lab.mjs (same folder) to e2e/. Runs against the BUILT site: pnpm build && pnpm test:e2e.
// It fails when a page breaks a budget: the plugin's defaults (Core Web Vitals "good", bytes, requests), tightened
// below to what this site measured, so a change that makes it slower fails. Loosen a number only with a reason.
import type { Browser } from '@playwright/test'
import { overBudget, perfBudgets } from '@intecion/ipal-kit/doctor'
import { chromium, expect, test } from '@playwright/test'
// a plain ES module (JSDoc types) — perf-lab.mjs from the skill's resources
import { measureMedian } from './perf-lab.mjs'
const runs = Number(process.env.PERF_RUNS ?? 1)
// Start from the defaults; after the first run, set each number to what you measured plus ~20 % (the lab is noisy).
const budgets = perfBudgets({
desktop: {},
mobile: {},
})
// One page of each template the site has (AGENTS.md → Site map). `budget` changes a number for one page, with a reason.
const PAGES: Array<{ budget?: Partial<typeof budgets.mobile>; name: string; path: string }> = [
{ name: 'home', path: '/pl' },
// { name: 'page', path: '/pl/o-nas' },
// { name: 'post', path: '/pl/blog/<a-post>' },
// { name: 'form', path: '/pl/kontakt', budget: { thirdParty: ['https://challenges.cloudflare.com'] } }, // Turnstile
]
let browser: Browser
test.beforeAll(async () => {
browser = await chromium.launch()
})
test.afterAll(async () => {
await browser?.close()
})
for (const page of PAGES) {
for (const profile of ['mobile', 'desktop'] as const) {
test(`${page.name} (${profile}) stays within its performance budget`, async ({ baseURL }) => {
test.setTimeout(120_000)
const measured = await measureMedian(browser, `${baseURL}${page.path}`, profile, runs)
test.info().annotations.push({ description: JSON.stringify({ bytes: measured.bytes, cls: measured.cls, inp: measured.inp, lcp: measured.lcp, requests: measured.requests }), type: 'measured' })
expect(overBudget(measured, { ...budgets[profile], ...page.budget }), `${page.path} ${profile}`).toEqual([])
if (measured.lcpElement?.tag === 'img') {expect(measured.lcpElement.loading, 'the LCP image is lazy').not.toBe('lazy')}
})
}
}
@@ -336,7 +336,7 @@ Opt-in with `iapl({ cookieScanner: true })`; the plugin wires the collection, en
|---|---|---|
| `createContentHelpers({ config, content?, i18n?, baseUrl?, … })` | `@intecion/ipal-kit` | factory for `src/lib/content.ts`: cached `getCachedPayload`, `getSettings`, `resolveRoute`, `getEntries`, `generatePageMetadata`, `getSiteShell`, `sitemap`, `robots`, `getRobots`, `isPathVisible`, `markdownRoute`, `healthRoute`, `mcpGET`/`mcpPOST`… — do not write these wrappers yourself |
| `createPageRoute(content, { blocks, notFound, permanentRedirect, redirect?, … })` | `@intecion/ipal-kit/rsc` | ready `[[...slug]]` catch-all page → `{ Page, generateMetadata, generateStaticParams }` (blocks, slug history redirects, JSON-LD, under-construction mode); does not paginate `?page=` |
| `createNotFoundPage(content, { load } \| { blocks, fallback?, … })` | `@intecion/ipal-kit/rsc` | default export of `not-found.tsx` — the 404 page chosen in the panel or a fallback (the lazy `load` variant is recommended) |
| `createNotFoundPage(content, { load, placeholder? } \| { blocks, fallback?, … })` | `@intecion/ipal-kit/rsc` | default export of `not-found.tsx` — the 404 page chosen in the panel or a fallback (the lazy `load` variant is recommended; `placeholder` (1.18.0) reserves the 404 content's height until it arrives — no layout shift, performance.md) |
| `renderNotFoundView(content, { blocks, fallback?, blockProps?, layoutField? }, locale)` | `@intecion/ipal-kit/rsc` | 404 content in one language — called from a server action for the lazy `createNotFoundPage({ load })` (pages.md) |
| `SiteProviders` | `@intecion/ipal-kit/rsc` | layout component: `shell={await getSiteShell(locale)}` mounts consent, cookie banner, analytics, Turnstile, site JSON-LD, theme script (and `lightbox` → `LightboxProvider`); `nonce` (from `x-nonce`) goes on the theme script and the GA4/GTM tag; does not mount `AlternateLinksProvider` |
@@ -530,7 +530,7 @@ The editor builds forms in the panel (Forms collection). The project does NOT wr
| Export | Import from | What it does / when |
|---|---|---|
| `mediaImageProps(resource, { sizes?, priority?, alt?, placeholderColor? })` | `@intecion/ipal-kit` | `next/image` props for an image upload (dimensions, focal point → `objectPosition`, blur placeholder, `preload` for LCP) or `null` (video/PDF/ID) — for your own `<Media>` |
| `mediaImageProps(resource, { sizes?, priority?, eager?, alt?, placeholderColor? })` | `@intecion/ipal-kit` | `next/image` props for an image upload (dimensions, focal point → `objectPosition`, blur placeholder, `preload` for LCP) or `null` (video/PDF/ID) — for your own `<Media>`. `eager` (1.18.0): above the fold but not the LCP image (a logo) — eager without high priority or a preload |
| `videoProps(resource, { mode?, poster?, reducedMotion? })` | `@intecion/ipal-kit` | `<video>` attributes for a video upload (`'background'`: autoplay/muted/loop; `'player'`: controls, `preload="none"`) or `null` |
| `MEDIA_SIZES` | `@intecion/ipal-kit` | Ready constant `sizes` values: `full`, `half`, `third`, `quarter`, `thumb` |
| `normalizeFilename(filename)` | `@intecion/ipal-kit` | Slugifies a file name, keeping the extension (`"Zdjęcie 1.JPG"` → `"zdjecie-1.jpg"`) |
@@ -876,7 +876,9 @@ Bin: `iapl-doctor` (`pnpm exec iapl-doctor [dir] [--json] [--md] [--strict] [--f
| `findFrontend(ctx)` | `@intecion/ipal-kit/doctor` | The folder of the site's pages (`FrontendLayout`: `dir`, `multi`, `ambiguous`, `missingOverride`) — found by structure (any route group with the catch-all page, a localized one first); `layout.frontend` in `iapl-doctor.json` wins. |
| `createLiveFetcher(url, { adminRoute, staging })` | `@intecion/ipal-kit/doctor` | Cached GET-only fetcher for the live rules. |
| `runDeepProbe(ctx)` | `@intecion/ipal-kit/doctor` | `pnpm exec payload run …/dist/modules/doctor/probe.js` in the project → `DoctorStatus`. |
| `collectDoctorStatus(payload)` | `@intecion/ipal-kit/doctor` | Read-only counts: `usersWithout2fa`, `pendingCookies`, `plugin`, `node`. |
| `collectDoctorStatus(payload)` | `@intecion/ipal-kit/doctor` | Read-only counts: `usersWithout2fa`, `pendingCookies`, `media` (images over `IMAGE_RULES`, 1.18.0), `plugin`, `node`. |
| `PERF_BUDGETS`, `SERVER_BUDGET`, `perfBudgets(overrides)`, `overBudget(measured, budget)`, `IMAGE_RULES` | `@intecion/ipal-kit/doctor` | Performance budgets (1.18.0, performance.md): the defaults per profile (`mobile`, `desktop`: `lcp`, `cls`, `inp`, `tbt`, `jsBytes`, `cssBytes`, `fontBytes`, `requests`, `renderBlocking`, `thirdParty`) and per render (`queriesPerRender`); a project's own on top; the broken budgets of one measurement as lines (empty = within budget); the image limits (1.5 MB, 2560 px, AVIF/WebP). Types `PerfBudget`, `PerfMeasurement`, `PerfProfile`, `ServerBudget`. The gate: `iapl-performance/resources/performance.spec.template.ts` + `perf-lab.mjs`. |
| `performanceRules` | `@intecion/ipal-kit/doctor` | The doctor's `performance` group (`perf-images-config`, `perf-fonts`, `perf-render-blocking`, `perf-embeds`, `perf-animations`, `perf-budgets`, `perf-live`, `perf-images`) — part of `doctorRules`. |
| `buildDoctorEndpoint({ tokenVar, access })` | `@intecion/ipal-kit/doctor` | `GET /ipal/doctor` (`/api/ipal/doctor`): 404 until the token variable (default `IAPL_DOCTOR_TOKEN`, ≥ 32 chars) is set, Bearer token or `access`, rate-limited. Added by `iapl` unless `doctor: false`. |
| `jobsRunAccess({ secretVar? })` | `@intecion/ipal-kit` | The rule iapl puts on `jobs.access.run` when the project writes none: `cronSecretMatches(req, process.env[secretVar])` or an admin with the second factor. Reuse it in your own rule: `run: (a) => jobsRunAccess()(a) \|\| myCheck(a)`. Type `JobsRunAccessOptions`. |
| `withJobsRunAccess(config, options \| false)` / `jobsRunNotice(config)` | `@intecion/ipal-kit` | The config with that rule (only when `jobs.access.run` is missing; marks `custom.iapl.jobsRunDefault`); the start-up line when the queue is on and the secret is missing (null otherwise). |
+136
View File
@@ -0,0 +1,136 @@
# Performance review 2026-12 — method, numbers, audit, decisions
The measurements and the audit behind [performance.md](../../performance.md) (1.18.0). Owner's brief (2026-12-01):
the site as light as possible, everything fast and optimised, good practice required, the audit and the doctor
check it, full documentation; page loading, elements, animations, resources, images.
## Method (repeatable)
```bash
docker run -d --rm --name iapl-perf-mongo -p 127.0.0.1:27277:27017 mongo:7 # any local MongoDB
# reference/.env: DATABASE_URI on that port, ALLOW_LOCAL_MEDIA=1, NEXT_PUBLIC_SERVER_URL=http://localhost:3370
pnpm build && (cd reference && pnpm install --ignore-workspace && pnpm seed && pnpm build)
pnpm perf:measure --label=webpack-after --mongo-container=iapl-perf-mongo # starts next start itself
(cd reference && pnpm exec next build --turbopack) && pnpm perf:measure --label=turbopack-after --mongo-container=iapl-perf-mongo
```
`scripts/perf-measure.mjs` + `reference/e2e/perf-lab.mjs`: Chromium (Playwright 1.65) with Lighthouse's profiles,
empty cache, median of 3 runs; eight page types × phone and desktop; `/admin/login`; cold start (spawn → `/api/health`),
RSS after the run, TTFB over 20 requests, and one render of each page with ISR bypassed (`x-prerender-revalidate`)
counted by MongoDB's profiler. Machine: Apple silicon, Node 22.23, MongoDB 7 in Docker, Next 16.4.6, Payload 3.94.1.
Raw results: `webpack-before.json`, `webpack-after.json`, `turbopack-before.json`, `turbopack-after.json` here.
"Before" = local main `ee241de` (1.17.2), "after" = this branch.
## Numbers
### Server: one render of a page (ISR bypassed), webpack build
| Page | Queries before → after | Render ms before → after |
|---|---|---|
| home `/pl` | 43 → 24 | 95 → 51 |
| page `/pl/o-nas` | 34 → 21 | 54 → 34 |
| archive `/pl/blog` | 34 → 23 | 63 → 42 |
| post | 41 → 26 | 61 → 41 |
| case study | 37 → 22 | 33 → 31 |
| form `/pl/wycena` | 30 → 19 | 28 → 29 |
| showcase `/pl/bloki` | 42 → 27 | 68 → 62 |
| 404 | 25 → 20 | 29 → 26 |
| `/md/pl`, `/llms.txt`, `/llms-full.txt`, `/sitemap.xml` | 16, 22, 38, 0 — unchanged | — |
All query time on a local MongoDB is ≤ 1 ms per render: the count is what costs on a remote database (one round trip
each — on Coolify's Docker network ~0.2–0.5 ms, more on a managed database). A cached (ISR) page answers in
3.5–3.7 ms median, 5.4 ms p95, with 0 queries, before and after. Cold start (spawn → health) 1.0–1.6 s; server RSS
after the run 340–440 MiB (noisy between runs; no change attributable to this branch).
### Client: lab, median of 3, phone (Slow 4G, CPU 4×) / desktop
| | Before (webpack) | After (webpack) | Before (Turbopack) | After (Turbopack) |
|---|---|---|---|---|
| JS per page, compressed | 191.3 KB | 188.1 KB | 184.4 KB | see turbopack-after.json |
| CSS | 11.0 KB | 11.0 KB | 12.0 KB | |
| Fonts | 209.5 KB | 209.5 KB | 209.5 KB | |
| Requests (home, phone) | 26 | 26 | 26 | |
| LCP phone (pages) | 788–832 ms | 780–828 ms | 796–836 ms | |
| LCP desktop | 284–316 ms | 288–300 ms | 284–300 ms | |
| CLS | 0 (home 0.036) | 0 (home 0.036) | 0 (home 0.036) | |
| TBT phone | 22–25 ms | 16–23 ms | 6–13 ms | |
| Tap response (INP proxy) | 32–40 ms | 32–48 ms | 32–48 ms | |
| Render-blocking | 1 (the stylesheet) | 1 | 1 | |
| 404: LCP / CLS (phone) | 2.49 s / 0.319 | 2.50 s / 0.319 | 2.37 s / 0.319 | |
| `/admin/login` JS | 843 KB | 843 KB | — | |
Lab numbers on localhost: LCP is the network profile plus render, so the differences between pages are small; the
budgets and the gate catch regressions, PageSpeed Insights shows the field.
## Audit — what the plugin does, file and line, and the gain of each fix
Sources: web.dev (vitals, optimize-lcp, cls, optimize-inp, font-best-practices, animations-guide,
prefers-reduced-motion, third-party-facades, render-blocking-resources, serve-images-avif-webp,
lcp-lazy-loading), nextjs.org/docs (caching, fonts, image, lazy-loading, package bundling), payloadcms.com/docs
(queries/depth, queries/select, database/indexes).
### Built in this branch (no change to how a site looks or how editors work)
| # | Finding (before) | Fix | Measured gain |
|---|---|---|---|
| S1 | `resolveRoute` was `cache()`d but called with `segments ?? []` — a new array each time, so React's identity comparison missed; the homepage was read in full at depth 2 (≈ 6 queries) four times per render (`src/modules/frontend/createContentHelpers.ts` resolveRoute; callers `pageRoute.tsx:123`, `createContentHelpers.ts` getPageJsonLd, `seo/createPageMetadata.ts:152`) | key by `JSON.stringify(segments ?? [])` | home 43 → 24 queries with S2–S4 |
| S2 | `generatePageMetadata` uncached: the page's metadata, the reference page's alternate links and `getPageJsonLd` each built it — three × (homepage + document read in every locale) | `cache()` keyed by value | −6 queries on every page |
| S3 | `slugsAcrossLocales` and `readSiteMetaConfig` read whole documents (layout in every locale) for the slug map (`seo/slugsAcrossLocales.ts:28`, `seo/readSiteMetaConfig.ts:78`) | `select: { slug: true }` | smaller reads (same count) |
| S4 | `getConsentTexts` → `readPrivacyPage` read Site settings at depth 1 in every locale, populating every system page, archive and allowed page in full (`consent/getConsentTexts.ts:138`) | `select: { privacyPolicy: true }` | fewer populated pages per render |
| S5 | analytics and Turnstile each read Site integrations in the same `Promise.all` (`frontend/createContentHelpers.ts` getSiteShell, `analytics/getAnalyticsConfig.ts:14`, `turnstile/config.ts:90`) | one in-flight read shared (`payload/getSiteIntegrations.ts`), nothing kept after it | −1 query per render (−2 with a form that has file blocks) |
| S6 | reference: `siteJsonLd` read the Company global again instead of the cached `getCompany` (`reference/src/lib/content.ts`) | the cached getter | −1 query per render |
| S7 | reference: `slugHistory.slug` without an index — queried on every unknown URL (`content/resolveRedirect.ts:96`) | `index: true` (reference `Pages.ts`, hooks.md) | a collection scan avoided per 404; nothing measurable at 30 pages |
| C1 | `src/exports/client.ts` and six module barrels carried `'use client'`: the barrel was one client boundary, so every page shipped every component behind it | the directive only on the leaf components | with C2: −3.2 KB compressed JS on every page |
| C2 | `LightboxProvider` imported the viewer statically (`lightbox/LightboxProvider.tsx:10`) | `lazy()` — loaded on the first open (7.3 KB raw chunk) | in C1 |
| C3 | `TableOfContents` measured every heading on every scroll event (`richtext/TableOfContents.tsx:38`) | at most once per frame (rAF) | fewer forced layouts while scrolling a long article (INP) |
| C4 | `Turnstile` polled every 300 ms for the life of the form (`turnstile/Turnstile.tsx:100`) | stop once rendered | no idle timer on form pages |
| C5 | the cookie banner's switches, its details chevron and the cookie button animated with no regard for reduced motion (`consent/CookieBanner.tsx:139,171,361`, `CookieButton.tsx:82`) | `motion-reduce:transition-none` | WCAG 2.3.3; no change without the setting |
| C6 | the reference header logo had `priority` — a second high-priority preload next to the hero (`reference/src/components/layout/Header.tsx:27`) | `Media eager` (new option: eager, no high priority, no preload) | the hero gets the first round trip (a site with a logo) |
| C7 | the lazy 404 could not reserve space | `createNotFoundPage({ load, placeholder })` (default unchanged) | CLS 0.32 → 0 when the project sets its 404 height |
### Already right (kept)
ISR for every page and 0 queries for a cached page; no `headers()` / `cookies()` in the layout; the consent banner
in the first paint (`docs/consent.md`); theme client hints only on `/admin`; `next/font` self-hosted with
`display: 'swap'`; one render-blocking stylesheet (11 KB); `mediaImageProps` sets dimensions, `sizes`, lazy and
the LCP `priority`; `buildImagesConfig` serves AVIF / WebP with a 31-day cache; upload limits with an opt-in
conversion (metadata dropped); `YouTubeEmbed` is a facade; Meta, LinkedIn, TikTok and Clarity wait for consent;
the proxy does no database work; the 434 KB cookie database is loaded only by a scan; the sitemap has `select` and a
300 s memo.
### For the owner — yes / no (gain and cost)
1. **Lazy 404 content (CLS 0.32, LCP 2.5 s on a phone).** The 404 is fetched by a server action after hydration
so that every page's payload does not carry it (pages.md). Options: (a) keep, and have the reference site set a
`placeholder` of its 404 height — CLS → 0, LCP unchanged, a number to keep in sync with the content; (b) render
the 404 eagerly — LCP and CLS as any page, but every page's HTML grows by the 404 content in every language
(pages.md: a two-language home page as the 404 made a page 195 KB gzip instead of 146 KB). Recommendation (a).
2. **Fonts: 209.5 KB, four preloaded files** (Inter + Fraunces, latin + latin-ext). Each variable family has two
subset files. Options: Fraunces `preload: false` (headings swap in late, fallback metrics keep CLS ~0) — −70 KB
of preloads competing with the hero; or one family. A design decision for the reference site and the starter
default. Gain on a phone: ~0.3 s less contention on Slow 4G; cost: a visible heading swap.
3. **Form code on every page (≈ 10 KB compressed).** The catch-all route renders any block, so the contact form's
client code (BuilderForm, Turnstile provider) is in every page's bundle. A `lazy()` wrapper would load it only on
pages with a form; SSR stays complete. Gain −10 KB on most pages; cost: a hydration wait on the form, test effort
with both bundlers. Recommendation: yes, next release.
4. **Background video and reduced motion.** `Media` (a server component) cannot know the visitor's setting, so a
background video autoplays for everyone (`block-library/ui/Media.tsx:29`). A small client wrapper pausing it with
`prefers-reduced-motion` adds ~1 KB to pages with a video. Recommendation: yes.
5. **Consent Mode `basic` as the default** (no request to Google before consent; already pending as a security
decision). Speed gain on a first visit with GA/GTM set: one third-party origin and ~100 KB of tag less until consent.
6. **Card hover animates `box-shadow`** (`block-library/ui/Card.tsx:6`, a paint per frame, cheap on cards). A
pseudo-element with `opacity` would be compositor-only; the hover looks the same. Low gain; yes if the block
library is touched anyway.
7. **Upload variants (`imageSizes`) and metadata on originals.** next/image already resizes and converts on request,
so stored variants mostly help the lightbox `srcSet` and R2 egress; originals under the 1.5 MB limit keep their
EXIF (camera, possibly GPS). Stripping metadata on every upload re-encodes the original. Recommendation: strip
metadata on upload for JPEG/PNG (privacy more than speed), variants no.
8. **Doctor performance rules: warnings now, errors later?** In 1.18.0 they warn (as asked); `perf-live`
uncompressed HTML and `perf-images` could become errors in 1.19.0.
### Shared with IAWL
Proposed for both products (performance.md §6): the Core Web Vitals targets and the lab profile; JS ≤ 250 KB,
CSS ≤ 50 KB, fonts ≤ 250 KB and two families, ≤ 40 requests on the phone, one render-blocking stylesheet, no
third-party origin before consent; images ≤ 1.5 MB and ≤ 2560 px at upload, AVIF / WebP in the width the screen
needs, one high-priority LCP image, lazy below the fold. Not shared: the database budget (MongoDB queries per render
here, SQL queries per request in WordPress).
+751
View File
@@ -0,0 +1,751 @@
{
"client": {
"mobile": {
"home": {
"bytes": {
"css": 11042,
"font": 209501,
"html": 19849,
"image": 9532,
"js": 188111,
"other": 24978
},
"cls": 0.036,
"fcp": 800,
"inp": 40,
"interaction": "PL",
"lcp": 800,
"lcpElement": {
"fetchpriority": "high",
"loading": "eager",
"src": "data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1600 1000'%3",
"tag": "img"
},
"load": 2495,
"profile": "mobile",
"renderBlocking": [
"/_next/static/css/3ca5a494a33af0a8.css"
],
"requests": 26,
"scriptMs": 118,
"status": 200,
"tbt": 18,
"thirdParty": [],
"ttfb": 151,
"url": "/pl",
"runs": 3
},
"page": {
"bytes": {
"css": 11042,
"font": 209501,
"html": 17076,
"image": 8451,
"js": 188111,
"other": 13192
},
"cls": 0,
"fcp": 796,
"inp": 32,
"interaction": "PL",
"lcp": 796,
"lcpElement": {
"fetchpriority": "high",
"loading": "eager",
"src": "data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1600 1000'%3",
"tag": "img"
},
"load": 2502,
"profile": "mobile",
"renderBlocking": [
"/_next/static/css/3ca5a494a33af0a8.css"
],
"requests": 21,
"scriptMs": 114,
"status": 200,
"tbt": 19,
"thirdParty": [],
"ttfb": 151,
"url": "/pl/o-nas",
"runs": 3
},
"archive": {
"bytes": {
"css": 11042,
"font": 209501,
"html": 16537,
"image": 5316,
"js": 188111,
"other": 18767
},
"cls": 0,
"fcp": 780,
"inp": 32,
"interaction": "PL",
"lcp": 780,
"lcpElement": {
"fetchpriority": null,
"loading": null,
"src": null,
"tag": "p"
},
"load": 2489,
"profile": "mobile",
"renderBlocking": [
"/_next/static/css/3ca5a494a33af0a8.css"
],
"requests": 22,
"scriptMs": 116,
"status": 200,
"tbt": 18,
"thirdParty": [],
"ttfb": 151,
"url": "/pl/blog",
"runs": 3
},
"post": {
"bytes": {
"css": 11042,
"font": 209501,
"html": 17062,
"image": 5316,
"js": 188111,
"other": 13192
},
"cls": 0,
"fcp": 796,
"inp": 40,
"interaction": "PL",
"lcp": 796,
"lcpElement": {
"fetchpriority": null,
"loading": null,
"src": null,
"tag": "p"
},
"load": 2488,
"profile": "mobile",
"renderBlocking": [
"/_next/static/css/3ca5a494a33af0a8.css"
],
"requests": 21,
"scriptMs": 110,
"status": 200,
"tbt": 16,
"thirdParty": [],
"ttfb": 151,
"url": "/pl/blog/zanim-kupisz-dzialke",
"runs": 3
},
"caseStudy": {
"bytes": {
"css": 11042,
"font": 209501,
"html": 16546,
"image": 4372,
"js": 188111,
"other": 13192
},
"cls": 0,
"fcp": 792,
"inp": 40,
"interaction": "PL",
"lcp": 792,
"lcpElement": {
"fetchpriority": null,
"loading": null,
"src": null,
"tag": "p"
},
"load": 2475,
"profile": "mobile",
"renderBlocking": [
"/_next/static/css/3ca5a494a33af0a8.css"
],
"requests": 20,
"scriptMs": 116,
"status": 200,
"tbt": 20,
"thirdParty": [],
"ttfb": 151,
"url": "/pl/realizacje/dom-pod-lasem",
"runs": 3
},
"form": {
"bytes": {
"css": 11042,
"font": 209501,
"html": 16279,
"image": 0,
"js": 188111,
"other": 13192
},
"cls": 0,
"fcp": 792,
"inp": 32,
"interaction": "PL",
"lcp": 792,
"lcpElement": {
"fetchpriority": null,
"loading": null,
"src": null,
"tag": "p"
},
"load": 2447,
"profile": "mobile",
"renderBlocking": [
"/_next/static/css/3ca5a494a33af0a8.css"
],
"requests": 18,
"scriptMs": 119,
"status": 200,
"tbt": 23,
"thirdParty": [],
"ttfb": 151,
"url": "/pl/wycena",
"runs": 3
},
"showcase": {
"bytes": {
"css": 11042,
"font": 209501,
"html": 36946,
"image": 2016,
"js": 216357,
"other": 25110
},
"cls": 0,
"fcp": 828,
"inp": 32,
"interaction": "PL",
"lcp": 828,
"lcpElement": {
"fetchpriority": "high",
"loading": "eager",
"src": "data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1600 1000'%3",
"tag": "img"
},
"load": 2464,
"profile": "mobile",
"renderBlocking": [
"/_next/static/css/3ca5a494a33af0a8.css"
],
"requests": 25,
"scriptMs": 170,
"status": 200,
"tbt": 20,
"thirdParty": [
"https://challenges.cloudflare.com"
],
"ttfb": 151,
"url": "/pl/bloki",
"runs": 3
},
"notFound": {
"bytes": {
"css": 11042,
"font": 209501,
"html": 7694,
"image": 0,
"js": 188111,
"other": 68916
},
"cls": 0.319,
"fcp": 2504,
"inp": 40,
"interaction": "PL",
"lcp": 2504,
"lcpElement": {
"fetchpriority": null,
"loading": null,
"src": null,
"tag": "p"
},
"load": 2587,
"profile": "mobile",
"renderBlocking": [],
"requests": 27,
"scriptMs": 194,
"status": 404,
"tbt": 0,
"thirdParty": [],
"ttfb": 151,
"url": "/pl/nie-ma-takiej-strony",
"runs": 3
}
},
"desktop": {
"home": {
"bytes": {
"css": 11042,
"font": 209501,
"html": 19849,
"image": 9274,
"js": 188111,
"other": 72052
},
"cls": 0.001,
"fcp": 292,
"inp": 40,
"interaction": "PL",
"lcp": 292,
"lcpElement": {
"fetchpriority": null,
"loading": null,
"src": null,
"tag": "h1"
},
"load": 482,
"profile": "desktop",
"renderBlocking": [
"/_next/static/css/3ca5a494a33af0a8.css"
],
"requests": 33,
"scriptMs": 46,
"status": 200,
"tbt": 0,
"thirdParty": [],
"ttfb": 41,
"url": "/pl",
"runs": 3
},
"page": {
"bytes": {
"css": 11042,
"font": 209501,
"html": 17076,
"image": 10676,
"js": 188111,
"other": 48402
},
"cls": 0,
"fcp": 292,
"inp": 32,
"interaction": "PL",
"lcp": 292,
"lcpElement": {
"fetchpriority": "high",
"loading": "eager",
"src": "/_next/image?url=http%3A%2F%2Flocalhost%3A3370%2Fapi%2Fmedia%2Ffile%2Flibrary.webp&w=750&q=75",
"tag": "img"
},
"load": 464,
"profile": "desktop",
"renderBlocking": [
"/_next/static/css/3ca5a494a33af0a8.css"
],
"requests": 28,
"scriptMs": 28,
"status": 200,
"tbt": 0,
"thirdParty": [],
"ttfb": 41,
"url": "/pl/o-nas",
"runs": 3
},
"archive": {
"bytes": {
"css": 11042,
"font": 209501,
"html": 16537,
"image": 4809,
"js": 188111,
"other": 65348
},
"cls": 0,
"fcp": 288,
"inp": 40,
"interaction": "PL",
"lcp": 288,
"lcpElement": {
"fetchpriority": null,
"loading": null,
"src": null,
"tag": "p"
},
"load": 468,
"profile": "desktop",
"renderBlocking": [
"/_next/static/css/3ca5a494a33af0a8.css"
],
"requests": 30,
"scriptMs": 32,
"status": 200,
"tbt": 0,
"thirdParty": [],
"ttfb": 41,
"url": "/pl/blog",
"runs": 3
},
"post": {
"bytes": {
"css": 11042,
"font": 209501,
"html": 17062,
"image": 4809,
"js": 188111,
"other": 48402
},
"cls": 0,
"fcp": 288,
"inp": 48,
"interaction": "PL",
"lcp": 288,
"lcpElement": {
"fetchpriority": null,
"loading": null,
"src": null,
"tag": "p"
},
"load": 469,
"profile": "desktop",
"renderBlocking": [
"/_next/static/css/3ca5a494a33af0a8.css"
],
"requests": 27,
"scriptMs": 32,
"status": 200,
"tbt": 0,
"thirdParty": [],
"ttfb": 41,
"url": "/pl/blog/zanim-kupisz-dzialke",
"runs": 3
},
"caseStudy": {
"bytes": {
"css": 11042,
"font": 209501,
"html": 16546,
"image": 9278,
"js": 188111,
"other": 48402
},
"cls": 0,
"fcp": 300,
"inp": 40,
"interaction": "PL",
"lcp": 300,
"lcpElement": {
"fetchpriority": null,
"loading": null,
"src": null,
"tag": "h1"
},
"load": 468,
"profile": "desktop",
"renderBlocking": [
"/_next/static/css/3ca5a494a33af0a8.css"
],
"requests": 28,
"scriptMs": 28,
"status": 200,
"tbt": 0,
"thirdParty": [],
"ttfb": 41,
"url": "/pl/realizacje/dom-pod-lasem",
"runs": 3
},
"form": {
"bytes": {
"css": 11042,
"font": 209501,
"html": 16279,
"image": 0,
"js": 188111,
"other": 48402
},
"cls": 0,
"fcp": 300,
"inp": 40,
"interaction": "PL",
"lcp": 300,
"lcpElement": {
"fetchpriority": null,
"loading": null,
"src": null,
"tag": "p"
},
"load": 475,
"profile": "desktop",
"renderBlocking": [
"/_next/static/css/3ca5a494a33af0a8.css"
],
"requests": 24,
"scriptMs": 31,
"status": 200,
"tbt": 0,
"thirdParty": [],
"ttfb": 41,
"url": "/pl/wycena",
"runs": 3
},
"showcase": {
"bytes": {
"css": 11042,
"font": 209501,
"html": 36946,
"image": 5263,
"js": 216414,
"other": 48402
},
"cls": 0,
"fcp": 292,
"inp": 40,
"interaction": "PL",
"lcp": 292,
"lcpElement": {
"fetchpriority": null,
"loading": null,
"src": null,
"tag": "p"
},
"load": 457,
"profile": "desktop",
"renderBlocking": [
"/_next/static/css/3ca5a494a33af0a8.css"
],
"requests": 30,
"scriptMs": 50,
"status": 200,
"tbt": 0,
"thirdParty": [
"https://challenges.cloudflare.com"
],
"ttfb": 41,
"url": "/pl/bloki",
"runs": 3
},
"notFound": {
"bytes": {
"css": 11042,
"font": 209501,
"html": 7694,
"image": 0,
"js": 188111,
"other": 85469
},
"cls": 0,
"fcp": 512,
"inp": 48,
"interaction": "PL",
"lcp": 576,
"lcpElement": {
"fetchpriority": null,
"loading": null,
"src": null,
"tag": "h1"
},
"load": 505,
"profile": "desktop",
"renderBlocking": [],
"requests": 31,
"scriptMs": 44,
"status": 404,
"tbt": 0,
"thirdParty": [],
"ttfb": 41,
"url": "/pl/nie-ma-takiej-strony",
"runs": 3
}
},
"admin": {
"bytes": {
"css": 98168,
"font": 0,
"html": 23081,
"image": 0,
"js": 843270,
"other": 1690
},
"cls": 0,
"fcp": 1024,
"inp": null,
"interaction": null,
"lcp": 1024,
"lcpElement": {
"fetchpriority": null,
"loading": null,
"src": null,
"tag": "a"
},
"load": 950,
"profile": "desktop",
"renderBlocking": [
"/_next/static/css/de3d54fcc6ee5dc6.css",
"/_next/static/css/c1e0b959dd828ab8.css",
"/_next/static/css/e5d1b6185968e333.css",
"/_next/static/css/4858144d3215dfc6.css",
"/_next/static/css/dc48c3ee3f159f65.css"
],
"requests": 20,
"scriptMs": 350,
"status": 200,
"tbt": 0,
"thirdParty": [],
"ttfb": 93,
"url": "/admin/login",
"runs": 3
}
},
"date": "2026-12-01T12:39:24.391Z",
"label": "webpack-after",
"method": "scripts/perf-measure.mjs + reference/e2e/perf-lab.mjs",
"runs": 3,
"server": {
"coldStartHealthMs": 1040,
"coldStartFirstPageMs": 1068,
"firstPageMs": 26,
"ttfb_home": {
"median": 3.7,
"p95": 5.4
},
"ttfb_md": {
"median": 26.7,
"p95": 31.9
},
"ttfb_sitemap": {
"median": 1.4,
"p95": 1.8
},
"ttfb_llms": {
"median": 36.4,
"p95": 53.7
},
"render": {
"home": {
"medianMs": 51,
"queries": 24,
"queryMs": 0,
"byCollection": {
"globals": 27,
"pages": 33,
"media": 9,
"forms": 3
}
},
"page": {
"medianMs": 33.8,
"queries": 21,
"queryMs": 0,
"byCollection": {
"globals": 27,
"pages": 27,
"media": 6,
"forms": 3
}
},
"archive": {
"medianMs": 42.1,
"queries": 23,
"queryMs": 0,
"byCollection": {
"globals": 27,
"media": 6,
"pages": 27,
"forms": 3,
"posts": 6
}
},
"post": {
"medianMs": 40.6,
"queries": 26,
"queryMs": 0,
"byCollection": {
"globals": 27,
"pages": 24,
"media": 9,
"posts": 15,
"forms": 3
}
},
"caseStudy": {
"medianMs": 30.8,
"queries": 22,
"queryMs": 0,
"byCollection": {
"globals": 27,
"pages": 21,
"media": 6,
"casestudies": 9,
"forms": 3
}
},
"form": {
"medianMs": 28.9,
"queries": 19,
"queryMs": 0,
"byCollection": {
"globals": 27,
"pages": 24,
"media": 3,
"forms": 3
}
},
"showcase": {
"medianMs": 61.8,
"queries": 27,
"queryMs": 0,
"byCollection": {
"globals": 24,
"pages": 33,
"media": 12,
"forms": 6,
"posts": 6
}
},
"notFound": {
"medianMs": 26.4,
"queries": 20,
"queryMs": 0,
"byCollection": {
"globals": 27,
"pages": 27,
"media": 6
}
},
"md": {
"medianMs": 30,
"queries": 16,
"queryMs": 0,
"byCollection": {
"globals": 4,
"media": 5,
"pages": 6,
"forms": 1
}
},
"sitemap": {
"medianMs": 3,
"queries": 0,
"queryMs": 0,
"byCollection": {}
},
"llms": {
"medianMs": 41,
"queries": 22,
"queryMs": 0,
"byCollection": {
"globals": 4,
"media": 3,
"pages": 7,
"posts": 4,
"casestudies": 4
}
},
"llmsFull": {
"medianMs": 65,
"queries": 38,
"queryMs": 0,
"byCollection": {
"globals": 6,
"media": 9,
"pages": 13,
"forms": 2,
"posts": 4,
"casestudies": 4
}
}
},
"rssMiB": 440
}
}
+14 -2
View File
@@ -2,7 +2,8 @@
`iapl-doctor` checks a site against the team's rules and lists every gap with a fix hint and a doc link. It covers
what drifts between sites: versions, Node, the folder layout, database names, env rules, security headers, 2FA, the
cookie scanner, the admin preview, the agent guide, seeds, the block library, and the running site.
cookie scanner, the admin preview, the agent guide, seeds, the block library, speed (images, fonts, embeds,
render-blocking resources, animations, budgets), and the running site.
Related: [AGENT.md §11](./agent/AGENT.md), the `iapl-doctor` skill, [deployment.md](./deployment.md),
[seeding.md](./seeding.md), [security.md](./security.md), [blocks.md](./blocks.md).
@@ -66,9 +67,12 @@ Added by `iapl` and **off until the site has `IAPL_DOCTOR_TOKEN`** (at least 32
returns counts only — never names, e-mails or values:
```json
{ "mail": { "graphEnv": false, "relay": { "connected": true, "disconnected": false, "nameReplaced": false, "state": "active" }, "replyAddress": true, "status": null, "transport": "relay" }, "node": "v22.20.0", "openSignUp": [], "pendingCookies": 0, "plugin": "1.15.0", "staffOnOwnRoles": [], "staffOpenToOthers": [], "turnstile": null, "turnstileSecretFromEnv": false, "usersSetupClosed": 0, "usersWithout2fa": 0 }
{ "mail": { "graphEnv": false, "relay": { "connected": true, "disconnected": false, "nameReplaced": false, "state": "active" }, "replyAddress": true, "status": null, "transport": "relay" }, "media": { "images": 42, "oversized": 0, "tooWide": 0 }, "node": "v22.20.0", "openSignUp": [], "pendingCookies": 0, "plugin": "1.15.0", "staffOnOwnRoles": [], "staffOpenToOthers": [], "turnstile": null, "turnstileSecretFromEnv": false, "usersSetupClosed": 0, "usersWithout2fa": 0 }
```
`media` (since 1.18.0): how many images the upload collections hold and how many are over the plugin's limits
(1.5 MB, 2560 px) — counts only, `null` without an upload collection.
`mail` (since 1.17.0): the e-mail transport in effect, the recorded state of sending and the site's state with the
Intecion mail service — states and codes only, never a token, a password or an address; `relay` is `null` when the
mail service is switched off.
@@ -134,6 +138,14 @@ Turn off: `iapl({ doctor: false })`. Adapt: `iapl({ doctor: { tokenVar: 'MY_TOKE
| | `blocks-duplicate` | warning | a project block whose `slug` (or `interfaceName`) matches a library block — also a slug renamed through the block's `slug` option — unless it is an override in `createBlockRegistry({ components })` |
| | `blocks-helper-copy` | warning | no local copy of a plugin field builder (`blockLibraryManifest.fieldBuilders`), `ctaHref`, `buildActionButtonsField` |
| | `blocks-tokens` | error / warning | from `iapl-audit`: hex colours, the token standard not wired, `iapl-tokens --check` |
| performance | `perf-images-config` | warning | `next.config` uses `buildImagesConfig()` (AVIF / WebP, R2, long cache) — [performance.md](./performance.md) |
| | `perf-fonts` | warning | no font from Google / Typekit hosts, no `font-display: block`, every `@font-face` has `font-display`, at most two `next/font` families |
| | `perf-render-blocking` | warning | no `<script src>` without `async` / `defer`, no stylesheet `<link>` or CSS `@import` from another host |
| | `perf-embeds` | warning | no `<iframe>` (map, widget) that loads with the page — a click-to-load facade, or `loading="lazy"`; YouTube is `iapl-audit`'s |
| | `perf-animations` | warning | no transition of a layout property or `transition-all`, no `scroll` listener, something honours `prefers-reduced-motion` when the site animates |
| | `perf-budgets` | info | a performance budget test in `e2e/` (the `iapl-performance` skill's template) |
| | `perf-live` | warning | (live) the home HTML is compressed, has no blocking `<script>` in `<head>`, preloads at most four fonts, its first image in `<main>` is not lazy, and is at most 150 KB |
| | `perf-images` | warning | (deep) no stored image over 1.5 MB or 2560 px wide (`IMAGE_RULES`) |
| audit | `i18n-literals` | error / warning | from `iapl-audit`: hardcoded text in blocks (error) and components (warning), Polish literals in code (not the panel's `adminText()` / `{ en, pl }` labels in a schema file — the `iapl-audit` skill) |
| | `audit:<title>` | as reported | every other `iapl-audit --quick` finding, one per file |
| live | `live-reachable`, `live-health`, `live-noindex`, `live-seo` | error / warning | the URL answers; `/api/health` 200; production not noindex (staging must be); every `iapl-seo-check` error and warning |
+1 -1
View File
@@ -163,7 +163,7 @@ export const Pages: CollectionConfig = {
fields: [
// ...
{ name: 'slugHistory', type: 'array', admin: { readOnly: true },
fields: [{ name: 'slug', type: 'text' }] },
fields: [{ name: 'slug', type: 'text', index: true }] }, // index: asked on every unknown URL (resolveRedirect)
],
hooks: { beforeChange: [trackSlugHistoryHook] },
}
+2 -1
View File
@@ -12,7 +12,8 @@ schema until you use it.
with a `srcSet` from every Payload image size.
- `RenderRichText lightbox` (`/rsc`) — click-to-enlarge for images in rich text.
- `useLightbox()` (`/client`) — open, close, next, previous for your own controls.
- `<LightboxDialog>` (`/client`) — the viewer itself, controlled, for full control.
- `<LightboxDialog>` (`/client`) — the viewer itself, controlled, for full control. Since 1.18.0 the provider loads it
the first time an image is opened (a separate chunk), so a page carries only the small provider and the triggers.
## What the visitor gets
+3 -1
View File
@@ -132,12 +132,14 @@ export function Media({ resource, priority, className }: Props) {
}
```
**`mediaImageProps(resource, { alt?, sizes?, priority?, placeholderColor? })`** → `next/image`
**`mediaImageProps(resource, { alt?, sizes?, priority?, eager?, placeholderColor? })`** → `next/image`
props or `null` (video, PDF, a bare id, no `width`/`height`):
- `width`/`height` from the document (no layout shift), `alt` from the document (override: `alt`, `''` for decoration);
- `sizes` defaults to `'100vw'` — give the real width (`MEDIA_SIZES`);
- `priority: true` (one LCP image per page) → `loading="eager"`, `fetchPriority="high"`, `preload`
(Next 16); otherwise `loading="lazy"`;
- `eager: true` (1.18.0; above the fold but not the LCP image — a header logo) → `loading="eager"` without
`fetchPriority` or a preload, so it does not compete with the one `priority` image; the library's `<Media eager>` too;
- focal point (≠ 50/50) → `style.objectPosition`;
- `placeholder.blurDataURL` → `placeholder="blur"`;
- `placeholder.color` → `style.backgroundColor` per `placeholderColor`: `'auto'` (default — JPEG only,
+5
View File
@@ -104,6 +104,11 @@ export default createNotFoundPage(content, { load: loadNotFoundView })
```
(`fallback` with JSX → file `notFoundView.tsx`.)
**Layout shift (1.18.0: `placeholder`).** The lazy content comes after hydration, so the footer moves when it arrives
(measured on the reference site: CLS 0.32 and LCP 2.5 s on a phone, [performance.md](./performance.md)). A block as tall
as your 404 content keeps the footer still: `createNotFoundPage(content, { load, placeholder: <div style={{ minHeight: '36rem' }} /> })`.
Default: nothing, as before. A fixed one-screen block is no fix: shorter content then pulls the footer up into view.
**Why lazy:** Next puts the layout's `not-found` tree into the RSC data (`self.__next_f`) of **every** page
under it — the router needs it for a client-side 404. The immediate variant renders the 404 page from the admin panel there
in every language, so every page carries it in its HTML (404 = home page with 2 languages: home page HTML
+148
View File
@@ -0,0 +1,148 @@
# Performance — a light, fast site by default
What the plugin does for speed without any project work, what a project must still do, the budgets every site is
held to, how to measure, and how to read the doctor's findings. The agent's short version is AGENT.md §6.11b and the
`iapl-performance` skill. The measurements and the audit behind this page: [dev/perf/README.md](./dev/perf/README.md).
Related: [media.md](./media.md), [frontend.md](./frontend.md), [consent.md](./consent.md), [doctor.md](./doctor.md),
[design-tokens.md](./design-tokens.md).
Targets on the built site, a phone on a slow connection (the numbers Google uses, [web.dev/articles/vitals](https://web.dev/articles/vitals)):
**LCP < 2.5 s, CLS < 0.1, INP < 200 ms.** The reference site measures LCP 0.8 s, CLS 0–0.04 and a 32–48 ms tap
response on that profile (the 404 page is the exception, below).
## 1. What the plugin does for you
| Area | Default | Change it |
|---|---|---|
| Static pages | `createPageRoute` + `generateStaticParams` + `revalidate`: every page is prerendered (ISR); nothing in the layout reads `headers()` or `cookies()`, so the HTML is cached and the server answers in ~4 ms | your own `render`; never call `headers()` in the layout ([nextjs.org/docs/app/guides/caching](https://nextjs.org/docs/app/guides/caching)) |
| Data per render | the `lib/content` helpers cache every read per request (`getSettings`, `resolveRoute`, `generatePageMetadata`, `getSiteShell`), keyed by value; Site settings at depth 1; one Site integrations read shared by analytics and Turnstile; reads that need one field `select` it | `createContentHelpers({ settingsDepth })`; your own getters with `cache()` |
| LCP image | `<Media priority>`: `fetchpriority="high"`, `loading="eager"` and a preload; everything else lazy with `sizes` | `priority` / `eager` / `sizes` per image (`MEDIA_SIZES`) |
| Image formats | `buildImagesConfig()`: AVIF and WebP, the width the screen needs, a 31-day cache, R2 allowed | `buildImagesConfig({ … })` ([media.md](./media.md)) |
| Upload limits | `buildOptimizeUploadHook()`: images over 1.5 MB or 2560 px wide are stopped; the editor may let the plugin shrink them (WebP, metadata dropped) | `maxImageBytes`, `maxImageWidth`, `quality` |
| No layout shift from images | width and height always from the document; a blur placeholder and the dominant colour (`buildMediaPlaceholderHook`) | `placeholderColor` |
| Embeds | `<YouTubeEmbed>`: a picture and a button; the iframe only after a click, from youtube-nocookie.com | `poster` |
| Client JavaScript | small client leaves; since 1.18.0 a page ships only the client components it renders (the `/client` barrels are no longer one client boundary) and the lightbox viewer loads on the first open | — |
| Third parties before consent | none besides Google's tag in Consent Mode `advanced` (all signals denied); Meta, LinkedIn, TikTok and Clarity wait for consent; Turnstile only on a form's last step | `analytics={{ consentMode: 'basic' }}` — no request to Google before consent; `analytics={{ defer: true }}` — the tag after the first interaction |
| Fonts | the reference layout uses `next/font` (self-hosted, `display: 'swap'`, fallback metrics against layout shift) | the project's own fonts |
| Motion | the token durations (`duration-fast`, `-base`, `-slow`) are 0 ms with `prefers-reduced-motion: reduce`; the cookie banner, its switches and the cookie button stop their transitions too | `motion-reduce:` classes |
| Admin only | Payload's colour-scheme client hints only on `/admin`, so a public page is requested once | `withSecurityConfig(…, { adminClientHints: false })` |
## 2. What a project must do
Every row is something the plugin cannot decide for you. `iapl-doctor --only performance` finds most of them.
**Page loading** ([web.dev/articles/optimize-lcp](https://web.dev/articles/optimize-lcp))
- Exactly one `<Media priority>` per page: the first image a visitor sees (the library's hero does this itself via
`leadsWithImage`). A header logo is `<Media eager>` — at once, but without competing with the hero.
- Nothing render-blocking but the one stylesheet: no `<script src>` without `async` in the layout (use `next/script`
or the plugin's `ConsentScript` / `Analytics`), no stylesheet or `@import` from another host
([web.dev/articles/render-blocking-resources](https://web.dev/articles/render-blocking-resources)).
- Keep the page static: no `headers()`, `cookies()` or `searchParams` in the layout or page tree.
**Elements** ([web.dev/articles/cls](https://web.dev/articles/cls))
- Images through `Media` (dimensions, `sizes`, lazy below the fold, never lazy for the LCP image —
[web.dev/articles/lcp-lazy-loading](https://web.dev/articles/lcp-lazy-loading)).
- Content that arrives after the first paint reserves its space. The lazy 404 is the plugin's own case:
`createNotFoundPage(content, { load, placeholder: <div style={{ minHeight: '36rem' }} /> })` with the height of your
404 content keeps the footer still.
- Maps, videos and widgets behind a click: a picture and a button ([web.dev/articles/third-party-facades](https://web.dev/articles/third-party-facades)).
**Fonts** ([web.dev/articles/font-best-practices](https://web.dev/articles/font-best-practices),
[nextjs.org/docs/app/getting-started/fonts](https://nextjs.org/docs/app/getting-started/fonts))
- `next/font` only, at most two families, variable fonts, `subsets: ['latin', 'latin-ext']` for Polish,
`display: 'swap'`. Every subset of every family is a preloaded file: two variable families with two subsets are
four files (the reference site: 209 KB). A third family or a second weight file is the first thing to cut.
**Animations** ([web.dev/articles/animations-guide](https://web.dev/articles/animations-guide),
[web.dev/articles/prefers-reduced-motion](https://web.dev/articles/prefers-reduced-motion))
- Only `transform` and `opacity`; never `height`, `top`, `margin`, `transition-all`.
- Reduced motion honoured: the token durations do it; anything else gets `motion-reduce:` or a media query.
- No work per `scroll` event: IntersectionObserver for "is it on screen", at most one update per frame
(`requestAnimationFrame`) for a reading position (the plugin's `TableOfContents` does this since 1.18.0).
**Resources** ([web.dev/articles/reduce-javascript-payloads-with-code-splitting](https://web.dev/articles/reduce-javascript-payloads-with-code-splitting))
- Server components by default; `'use client'` on the small interactive leaf, not the section.
- Compression on: Next compresses by itself; behind Coolify's proxy check that the HTML arrives with
`Content-Encoding` (`iapl-doctor --url` does). Next names its static files by content and serves them
`immutable` — nothing to do.
- No third-party request before consent (the consent rules, [consent.md](./consent.md)).
**Images** ([web.dev/articles/serve-images-avif-webp](https://web.dev/articles/serve-images-avif-webp),
[nextjs.org/docs/app/api-reference/components/image](https://nextjs.org/docs/app/api-reference/components/image))
- `images: buildImagesConfig()` in `next.config`; `buildOptimizeUploadHook()` and `buildMediaPlaceholderHook()` on the
media collection (the reference `Media.ts`).
- `sizes` = the width on screen (`MEDIA_SIZES.half`, `.third`, …): without it a phone downloads the full width.
- Images uploaded before the limits: `iapl-doctor --deep` counts those over 1.5 MB or 2560 px.
**Server** ([payloadcms.com/docs/queries/depth](https://payloadcms.com/docs/queries/depth),
[payloadcms.com/docs/queries/select](https://payloadcms.com/docs/queries/select))
- Read through `lib/content` (cached per request). Your own getters: `cache()` with primitive arguments — React
compares arguments by identity, so an array or an object argument never hits the cache.
- `depth` as low as the page needs; `select` when you need one field; no `findByID` in a loop.
- An index on fields you query: `index: true` on the slug (the plugin's `buildSlugField` does), on `slugHistory.slug`
(old addresses, asked on every unknown URL), on anything you filter a list by.
## 3. Budgets
The plugin's defaults (`PERF_BUDGETS` from `@intecion/ipal-kit/doctor`), per page, first visit:
| | Phone (Slow 4G, CPU 4×) | Desktop |
|---|---|---|
| LCP | 2500 ms | 1200 ms |
| CLS | 0.1 | 0.1 |
| INP (one scripted tap, Event Timing) | 200 ms | 100 ms |
| Total Blocking Time | 200 ms | 100 ms |
| JavaScript (compressed) | 250 KB | 250 KB |
| CSS (compressed) | 50 KB | 50 KB |
| Fonts | 250 KB | 250 KB |
| Requests | 40 | 50 |
| Render-blocking resources | 2 | 2 |
| Third-party origins before consent | none | none |
| Database queries per render (`SERVER_BUDGET`) | 40 | |
A project tightens them to what it measured (`perfBudgets({ mobile: { jsBytes: 200_000 } })`) in
`e2e/performance.spec.ts` (the `iapl-performance` skill's template): from then on the test fails when a change
makes a page slower. The reference site's gate (`reference/e2e/performance.spec.ts`, run by `pnpm e2e:built` with
both bundlers) holds each page type to its own numbers and counts the database queries of one render.
## 4. How to measure
- **The lab, per page** — `perf-lab.mjs` (the skill's `resources/`, the reference site's `e2e/`): Chromium with
Lighthouse's profiles (phone 412×823, Slow 4G — 150 ms, 1.6 Mbit/s — and a 4× slower CPU; desktop 1350×940,
40 ms, 10 Mbit/s), an empty cache, the median of several runs. It returns TTFB, FCP, LCP and the LCP element, CLS,
TBT, the response to one tap, script time, bytes per type, requests, render-blocking resources and third-party
origins.
- **The plugin repository** — `pnpm perf:measure --label=<name> --mongo-container=<docker name>` on the built
reference site: the lab numbers for eight page types on both profiles, the panel's sign-in page, cold start,
memory, TTFB, and the database queries of one render of each page (MongoDB's profiler; the render bypasses the ISR
cache with Next's own `x-prerender-revalidate` header). JSON in `docs/dev/perf/`.
- **The running site** — `pnpm exec iapl-doctor --url https://example.pl --only perf-live`, and PageSpeed Insights
for the field data of real visitors (28 days).
- Never measure `next dev`: it compiles on request and ships unminified code.
## 5. The doctor's findings
All in the `performance` group (`iapl-doctor --only performance`), warnings in 1.18.0 (`perf-budgets` is info):
| Rule | Source | It means | Fix |
|---|---|---|---|
| `perf-images-config` | static | `next.config` has no `buildImagesConfig()` | `images: buildImagesConfig()` |
| `perf-fonts` | static | a font from Google / Typekit, `font-display: block`, `@font-face` without `font-display`, more than two families | `next/font`, `display: 'swap'`, two families |
| `perf-render-blocking` | static | a `<script src>` without `async` / `defer`, a stylesheet or `@import` from another host | `next/script`, the plugin's script components, self-host |
| `perf-embeds` | static | an `<iframe>` (map, widget) that loads with the page (YouTube is `iapl-audit`'s) | a facade (picture + button), or `loading="lazy"` below the fold |
| `perf-animations` | static | a transition of a layout property, `transition-all`, a `scroll` listener, animations with nothing for reduced motion | `transform` / `opacity`, IntersectionObserver, `motion-reduce:` |
| `perf-budgets` | static | no performance budget test in `e2e/` | the skill's template |
| `perf-live` | `--url` | the HTML is not compressed; blocking scripts in `<head>`; more than four preloaded fonts; the first image in `<main>` is lazy; the home HTML over 150 KB | proxy compression; `async`; fewer font files; `priority`; less data to client components |
| `perf-images` | `--deep` | images stored over 1.5 MB or 2560 px wide | re-upload prepared, or tick "Optimise large image" |
Silence a finding with a reason in `iapl-doctor.json` like any other ([doctor.md](./doctor.md)).
## 6. Shared with IAWL
IAWL (the WordPress line) holds its sites to the same numbers where the measurement is the same: the Core Web Vitals
targets and lab profile, JS ≤ 250 KB, CSS ≤ 50 KB, fonts ≤ 250 KB and two families, requests ≤ 40 on the phone,
one render-blocking stylesheet, no third-party origin before consent, and the image rules (`IMAGE_RULES`): uploads
≤ 1.5 MB and ≤ 2560 px, served as AVIF / WebP in the width the screen needs, metadata dropped on conversion, one
high-priority LCP image, lazy below the fold. The database budget is per product (Payload counts MongoDB queries per
render; WordPress counts SQL queries per request).