17 KiB
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.
Related: media.md, frontend.md, consent.md, doctor.md, design-tokens.md.
Targets on the built site, a phone on a slow connection (the numbers Google uses, 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) |
| 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) |
| 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)
- Exactly one
<Media priority>per page: the first image a visitor sees (the library's hero does this itself vialeadsWithImage). A header logo is<Media eager>— at once, but without competing with the hero. - Nothing render-blocking but the one stylesheet: no
<script src>withoutasyncin the layout (usenext/scriptor the plugin'sConsentScript/Analytics), no stylesheet or@importfrom another host (web.dev/articles/render-blocking-resources). - Keep the page static: no
headers(),cookies()orsearchParamsin the layout or page tree.
Elements (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). - 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).
Fonts (web.dev/articles/font-best-practices, nextjs.org/docs/app/getting-started/fonts)
next/fontonly, 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, web.dev/articles/prefers-reduced-motion)
- Only
transformandopacity; neverheight,top,margin,transition-all. - Reduced motion honoured: the token durations do it; anything else gets
motion-reduce:or a media query. - No work per
scrollevent: IntersectionObserver for "is it on screen", at most one update per frame (requestAnimationFrame) for a reading position (the plugin'sTableOfContentsdoes this since 1.18.0).
Resources (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 --urldoes). Next names its static files by content and serves themimmutable— nothing to do. - No third-party request before consent (the consent rules, consent.md).
Images (web.dev/articles/serve-images-avif-webp, nextjs.org/docs/app/api-reference/components/image)
images: buildImagesConfig()innext.config;buildOptimizeUploadHook()andbuildMediaPlaceholderHook()on the media collection (the referenceMedia.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 --deepcounts those over 1.5 MB or 2560 px.
Server (payloadcms.com/docs/queries/depth, 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. depthas low as the page needs;selectwhen you need one field; nofindByIDin a loop.- An index on fields you query:
index: trueon the slug (the plugin'sbuildSlugFielddoes), onslugHistory.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'sresources/, the reference site'se2e/): 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 ownx-prerender-revalidateheader). JSON indocs/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 | the project runs Playwright but has 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).
6. What grows — keeping the site and its database small over the years
Measured on the reference site after a full test run (MongoDB; average record without indexes): a consent record 185 B, a form submission 647 B, a key-value entry 371 B, a page 9 KB. Every collection also carries 2–6 indexes.
| What | Grows with | What the plugin does (1.18.0) | What the project decides |
|---|---|---|---|
Consent log (consent-records) |
one record per banner choice | deleted after retentionDays (default 1095 — three years, the proof-of-consent period); the purge runs at most once a day, after a new record |
consentLog: { retentionDays } |
Statistics (stats-visits, opt-in) |
one record per visit | deleted after retentionDays (default 90), same purge |
stats: { retentionDays } |
| Form submissions | one per sent form (files are never stored: they go out by e-mail) | kept until deleted in the panel — unless forms: { submissionRetentionDays } is set (1.18.0), then deleted after that many days, once a day after a new submission |
the retention: personal data, a client decision (AGENTS.md → Project decisions) |
| Versions and drafts | every save | the plugin turns versions on nowhere; Payload keeps 100 per document by default (maxPerDoc, max for globals) |
a lower limit where you turn versions on: versions: { maxPerDoc: 20 }; never 0 (unlimited) |
payload-kv |
2FA attempt counters (one per staff account), the mail service state (one per host), enrolment nonces | expired mail-service nonces are swept (at most once a day, when the next enrolment starts); counters and state are bounded by accounts and hosts | — |
| Cookie review (opt-in) | distinct cookie names | upserted by name; a cookie that disappears is marked gone, not deleted (the history of what the site set) |
delete old gone rows in the panel when the client agrees |
payload-preferences, payload-locked-documents, payload-jobs |
panel users, open documents, queued jobs | Payload removes them with the user, on save, and on completion (deleteJobOnComplete); the plugin queues no jobs |
— |
| Media | uploads | Payload deletes the files (and R2 objects) with the document; nothing deletes media nobody uses | review growth-media findings in the panel |
.next/cache/images |
each image × width × format (AVIF + WebP) | kept 31 days per variant (minimumCacheTTL); Next caps nothing by size |
no persistent volume on .next in Coolify: every deploy starts empty |
| ISR output | pages × languages | rewritten in place on each revalidation | — |
| Logs | — | the plugin writes no files; it logs to stdout (Coolify keeps the container's log) | Coolify's log retention |
Postgres and SQLite: the same purges (one DELETE … WHERE created_at < …); no TTL indexes; the doctor reports
counts but not sizes. A consent log without its migration records nothing and so never purges.
What a project schedules: nothing for the plugin's own logs — the purges run inside the site. A site that gets
no new consent records (or submissions) for a long time keeps the old ones until the next one comes; the doctor's
growth-retention rule says so. Database backups are the hosting's job (Coolify → the MongoDB resource → Backups).
How to check: pnpm exec iapl-doctor --deep --only growth (or --url with IAPL_DOCTOR_TOKEN): document
counts, sizes (MongoDB), the oldest record, versions per collection and global, expired KV entries, media no
document points at; and on the machine it runs on, the image cache and the local upload folder. Thresholds in
iapl-doctor.json:
{ "growth": { "maxDocs": 200000, "maxMB": 512, "maxVersions": 50000, "submissionDays": 730, "expiredKv": 1000, "orphanedMedia": 25, "imageCacheMB": 1024, "uploadsMB": 2048 } }
| Rule | Source | It means |
|---|---|---|
growth-size |
deep | a collection over maxDocs documents or maxMB (data + indexes, MongoDB) |
growth-versions |
deep | a collection or global keeps versions without a limit, or over maxVersions |
growth-retention |
deep | a log with a retention holds records older than it: its purge has not run |
growth-submissions |
deep | form submissions kept without a retention (info; a warning when the oldest is over submissionDays) |
growth-kv |
deep | more than expiredKv expired entries in payload-kv |
growth-media |
deep | media nothing points at (info; a warning over orphanedMedia). Counted from the first 5000 documents |
growth-disk |
static | .next/cache/images over imageCacheMB, the local media/ folder over uploadsMB (info) |
None of these rules deletes anything; the plugin never deletes media or submissions by itself.
7. 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).