payload-performance
Skill0 starsChanged 13 days agoMITView on GitHub
Speed and cache cost for Payload CMS 3 + Next.js 16 sites on Vercel - static rendering, precise on-publish invalidation designed as a metered cost (no shared tags, no layout-wide revalidation, per-document targets, invalidation map), two-argument revalidateTag, lean Payload queries, function and database region pairing, small bundles, lazy loading, fonts, third-party scripts, and Core Web Vitals. Use when writing any revalidation hook or cache tag, when ISR writes or usage are high, pages are slow or stale, bundles are large, or before launch.
In this repository20 other files it gives its agents.
- AGENTS.mdAGENTS.md
- agent-guardrailsSkill
- creative-frontendSkill
- figma-handoffSkill
- payload-admin-brandingSkill
- payload-auth-rbacSkill
- payload-bookings-paymentsSkill
- payload-bootstrapSkill
- payload-deploy-vercelSkill
- payload-forms-crmSkill
- payload-integrationsSkill
- payload-legal-trustSkill
- payload-live-previewSkill
- payload-localizationSkill
- payload-mcpSkill
- payload-mediaSkill
- payload-project-kickoffSkill
- payload-seo-geoSkill
- payload-testingSkill
- project-architectureSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
16 rules. About 0 are common, 7 are distinctive, and 9 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈7
Distinctive · estimate
This author's own choices. Worth a look.
9
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 15
Use the template's model. Do not invent another.
- Very specific: line 29
Every revalidation hook checks context.disableRevalidate and skips draft-only changes.
- Very specific: line 30
Never wrap draft-mode queries in a cache (see payload-live-preview).
- Very specific: line 31
Do not enable cacheComponents in Payload 3 projects.
- Distinctive: line 46
Broader invalidation must state its reason and cost: If you deliberately invalidate more than the change requires, the code comment says …
- Very specific: line 50
Before delivery, fill in the invalidation map in PROJECT.md: one row per collection and global, listing which routes regenerate on a save …
- Very specific: line 57
Add index: true to fields used in where and sort (slug, _status, publishedAt, status, startsAt).
- Distinctive: line 64
Create the Turso database in the region closest to the client's visitors.
- Very specific: line 72
Import specific modules, never whole libraries (import { motion } from 'motion/react', not a full bundle).
- Very specific: line 74
Never ship the Payload Local API, payload-types runtime values, or server SDKs (stripe, googleapis) to the client.
- Very specific: line 84
Follow payload-media for image loaders, sizes, and video facades.
- Very specific: line 92
Prefer @next/third-parties for Google Analytics and Google Tag Manager.
- Distinctive: line 93
No chat widgets or heatmaps on initial load.
- Distinctive: line 97
Run Lighthouse in Chrome DevTools (mobile, simulated throttling) on the home page, a post, and the booking page.
- Distinctive: line 98
Check field data in Vercel Speed Insights (free tier) or PageSpeed Insights after launch.
- Distinctive: line 99
After launch, check ISR Writes on the Vercel Usage page weekly for the first month.
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Payload performance
Targets on a mid-range phone over 4G: LCP under 2.5 s, INP under 200 ms, CLS under 0.1.
Step 1: Rendering and caching model
Use the template's model. Do not invent another.
| Data | How it is rendered | How it refreshes |
| Pages, posts, legal pages, services | Static, prebuilt with generateStaticParams | Exact paths from the collection's targets function, on publish |
| Listings (posts index, category pages, home sections) | Static | Listed explicitly in the targets of the documents they render |
| Header, footer, site settings (layout-rendered globals) | unstable_cache with tag global_<slug> | That global's own afterChange hook only |
| Sitemaps | Cached with tag <collection>-sitemap | Targets of that collection, on publish |
| Drafts (live preview) | Dynamic through draft mode | Never cached |
| User-specific data (booking slots, account) | Dynamic, fetched with TanStack Query from a route handler | Query staleTime |
General rules:
- Next.js 16 requires two arguments:
revalidateTag(tag, profile). Payload hooks run in route handlers, so use{ expire: 0 }when editors expect to see changes on the next visit. Never call the deprecated single-argument form. - Every revalidation hook checks
context.disableRevalidateand skips draft-only changes. Seed scripts and migrations setcontext: { disableRevalidate: true }, becauserevalidatePaththrows outside a Next.js request. - Never wrap draft-mode queries in a cache (see
payload-live-preview). - Do not enable
cacheComponentsin Payload 3 projects; the official templates do not use it.
Step 2: Design invalidation as a cost
Every revalidated path regenerates on its next visit, and each regeneration is a metered ISR write on Vercel. Hobby has a fixed monthly ISR write allowance (200K at the time of a 2026-11 production audit). When it runs out, pages stop regenerating until the billing cycle resets: the site stays up, but content silently freezes. In that audit, a low-traffic bilingual site used 72% of the allowance (about 4,800 writes per day) because of two patterns this step forbids.
Rules:
- No shared cache tags on content queries. Detail queries carry only
<collection>:<docSlug>. Listing queries carry onlycollection:<slug>. Never put the collection tag on detail queries, and never put one tag (such ascms-content) on every query. A tag may be global only when the data renders in the layout (global_header), and it is invalidated only when that global changes. - Compute invalidation from the change. Revalidate the collection, the document's own tag, and the routes that actually render the document: its detail page, the listings that show it, and the home page only if the document is featured there. Nothing else.
revalidatePath(path, 'layout')is forbidden except in hooks for layout-rendered globals, and every use carries a comment naming the layout data that justifies it. Prefer the global tag even then.- Never pair
revalidate: falsecaches with broad invalidation. When pages depend entirely on tags, tag precision is the cost model. - Media and other supporting collections revalidate narrowly. A new upload revalidates nothing, because nothing references it yet. An edit to an existing file revalidates only the published documents that reference it.
- Batch operations revalidate once. Imports, seeding, bulk issuance, and scripts pass
context: { disableRevalidate: true }on every Local API call, then apply one combined set of targets at the end. - No timers on pages covered by targets. The template's posts index and its pagination pages export
revalidate = 600, so each one can regenerate every 10 minutes per locale while it gets traffic, even when nothing changed. Once a page is listed in a collection's targets, remove its time-basedrevalidateexport and keepdynamic = 'force-static'. - Broader invalidation must state its reason and cost. If you deliberately invalidate more than the change requires, the code comment says why and how many writes each save causes.
Implementation (targets helper, per-collection targets, media hook, global hook, batch pattern): references/invalidation-design.md.
Before delivery, fill in the invalidation map in PROJECT.md: one row per collection and global, listing which routes regenerate on a save and the write cost (paths × locales). If any ordinary content type regenerates every route, the design fails review.
Step 3: Lean Payload queries
- Pass
selectwith only the fields the component renders, and the lowestdepththat works (usually 0 or 1). - Set
defaultPopulateon collections that are often referenced (the template does this for pages and posts) so relationships return onlytitleandslug. - Lists use
limitand pagination. Usepagination: falseonly for small, bounded queries. - Add
index: trueto fields used inwhereandsort(slug,_status,publishedAt,status,startsAt). - Wrap per-request queries in React
cache()sogenerateMetadataand the page share one query.
Step 4: Pair function and database regions
Most latency on Vercel + Turso comes from the distance between the function and the database.
- Create the Turso database in the region closest to the client's visitors.
- Set the same region for Vercel functions in
vercel.json:{ "regions": ["fra1"] }(use the matching Vercel region code). - Record both in
PROJECT.md.
Step 5: JavaScript
- Server Components by default.
'use client'goes on the smallest interactive leaf, not on layouts or sections. - Heavy client libraries (3D, maps, rich animation timelines, charts) load with
next/dynamicinside a client component, and only when visible or on interaction. - Import specific modules, never whole libraries (
import { motion } from 'motion/react', not a full bundle). - One library per job: one animation library, one icon set, one date library.
- Never ship the Payload Local API,
payload-typesruntime values, or server SDKs (stripe,googleapis) to the client. Server-only modules start withimport 'server-only'.
Step 6: CSS and fonts
- Tailwind CSS only generates used classes. Do not import full CSS files from component or animation libraries; copy the few rules you need.
- Load fonts with
next/font(Google or local), withsubsetslimited to the scripts the site uses anddisplay: 'swap'. At most two families. - Variable fonts over multiple static weights.
Step 7: Images, video, and below-the-fold content
- Follow
payload-mediafor image loaders,sizes, and video facades. - Exactly one image per page gets
preload: the LCP image. - Below-the-fold sections that need client code render a lightweight placeholder and hydrate on visibility.
- Reserve space for every embed, image, and ad slot to avoid layout shift.
Step 8: Third-party scripts
- Analytics and tags load only after consent (
payload-legal-trust) and throughnext/scriptwithstrategy="afterInteractive"or"lazyOnload". - Prefer
@next/third-partiesfor Google Analytics and Google Tag Manager. - No chat widgets or heatmaps on initial load; load them on interaction.
Step 9: Measure
- Run Lighthouse in Chrome DevTools (mobile, simulated throttling) on the home page, a post, and the booking page.
- Check field data in Vercel Speed Insights (free tier) or PageSpeed Insights after launch.
- After launch, check ISR Writes on the Vercel Usage page weekly for the first month. Compare against the invalidation map: writes per day should be close to (saves per day × writes per save) plus first visits after deploys.
- Record the scores and the ISR baseline in
PROJECT.md. Fix the largest regression first.
Done when
- Publishing a post shows the change on the next visit; saving a draft does not revalidate anything
- Invalidation map in
PROJECT.mdlists every collection and global; no ordinary content type regenerates every route - For each collection, one traced save regenerates exactly the routes in its map row (verified with the hook's log line)
- Uploading a new media file revalidates nothing
- No tag is shared by all content queries; detail queries do not carry the collection tag
- Every
revalidatePath(..., 'layout')call is in a layout-global hook and has a justifying comment (search for'layout')) - No page covered by a targets function exports a time-based
revalidate(search forexport const revalidate) - No single-argument
revalidateTagcalls remain (search the codebase forrevalidateTag() - Function region matches the Turso region
- Lighthouse mobile Performance is 90 or higher on the home page and a post page
- No server-only package appears in client bundles
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

