{
  "id": "ai-rules-for-static-site-performance",
  "type": "rules",
  "category": "rules",
  "locale": "de",
  "url": "/de/rules/ai-rules-for-static-site-performance",
  "title": "KI-Codierregeln für die Leistung statischer Websites",
  "description": "AGENTS.md-Regeln für die Leistung statischer Websites, die Core Web Vitals, Bildoptimierung, Schriftarteinbindung durchsetzen und verhindern, dass Agenten renderblockierende Ressourcen ausliefern.",
  "tools": [
    "Cursor",
    "Claude Code",
    "Codex",
    "Windsurf"
  ],
  "stack": [
    "Astro",
    "Next.js",
    "TypeScript",
    "Tailwind"
  ],
  "tags": [
    "agents-md",
    "astro",
    "nextjs",
    "tailwind",
    "seo",
    "conventions"
  ],
  "difficulty": null,
  "updated": "2026-06-08",
  "markdown": "Legen Sie dies als `AGENTS.md` im Stammverzeichnis Ihres Repositorys ab. Leistungsregeln sind besonders wichtig für KI-generierten Code, da Agenten auf Korrektheit optimieren und ohne explizite Anweisung selten Bundle-Größe, renderblockierende Ressourcen oder Layout-Verschiebungen berücksichtigen.\n\n## AGENTS.md\n\n```md title=\"AGENTS.md\"\n# Project Rules — Static Site Performance\n\n## Core Web Vitals targets\n- LCP (Largest Contentful Paint): < 2.5 s on a simulated 4G mobile connection.\n- CLS (Cumulative Layout Shift): < 0.1. All images, ads, and embeds must have\n  explicit `width` and `height` attributes (or `aspect-ratio` CSS) to reserve space.\n- FID / INP (Interaction to Next Paint): < 200 ms. Minimise main-thread JavaScript.\n- These are not aspirational — they are definition-of-done criteria for any page change.\n\n## Images — highest impact\n- Never use bare `<img>` tags. Use the framework's image component:\n  - Astro: `<Image />` from `astro:assets`\n  - Next.js: `<Image />` from `next/image`\n- Serve images in WebP or AVIF. No JPEG/PNG without a `<picture>` element with\n  a next-gen format source.\n- Hero images (above the fold) must use `loading=\"eager\"` and `fetchpriority=\"high\"`.\n  All other images use `loading=\"lazy\"` (the default in the framework image components).\n- Never inline large base64-encoded images in HTML or CSS. Images above 2 KB should\n  be served as separate files and cached by the CDN.\n- Always provide `alt` text. Decorative images use `alt=\"\"`. Informational images\n  describe their content in under 125 characters.\n\n## Fonts\n- Fonts must be self-hosted (from `public/fonts/` or via the framework's font module).\n  Never load fonts from Google Fonts in production — it adds a cross-origin DNS lookup\n  and blocks rendering on slow connections.\n- Use `font-display: swap` in all `@font-face` declarations.\n- Preload only the primary font file (the weight used for body text):\n  `<link rel=\"preload\" as=\"font\" type=\"font/woff2\" crossorigin>`.\n  Preloading every weight defeats the purpose.\n- Limit to 2 font families per site (e.g. one for headings, one for body). Every\n  additional font family is an additional blocking resource.\n\n## JavaScript — bundle discipline\n- Every JS file added to the `<head>` must have `defer` or `async`. No synchronous\n  scripts in `<head>` — they block HTML parsing.\n- Third-party scripts (analytics, chat widgets, consent banners) must be loaded after\n  the page is interactive. Use `type=\"module\"` + dynamic `import()` or the framework's\n  `client:idle` / `strategy=\"lazyOnload\"` equivalents.\n- Do not add a JavaScript dependency for something that can be done in CSS or HTML.\n  Parallax, smooth scroll, sticky headers, and CSS animations do not need JavaScript.\n- Run `bundlephobia.com` or check `npx bundlephobia <package>` before adding any\n  new npm package. Document the gzipped size in the PR description.\n\n## CSS\n- Tailwind CSS purges unused classes at build time — this is the correct approach.\n  Do not add a global CSS file that imports every utility class from a library.\n- Never use `@import url(...)` inside a CSS file for non-local resources. This is\n  a render-blocking network request.\n- Critical above-the-fold CSS may be inlined in `<style>` in the `<head>`. Non-critical\n  CSS must be loaded asynchronously (`rel=\"preload\" as=\"style\"` + `onload` swap trick\n  or the framework's equivalent).\n\n## HTML and document structure\n- Set `<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">` on\n  every page. Missing this causes mobile browsers to render at desktop width.\n- Use `<link rel=\"preconnect\">` for essential third-party origins (CDNs, API hosts)\n  that are always needed on page load. Limit to 3 or fewer origins.\n- Minify HTML output. Astro and Next.js do this by default — do not disable it.\n\n## Definition of done\n- `astro build` or `next build` completes without warnings.\n- Lighthouse performance score ≥ 90 on mobile for any changed page.\n- No `<img>` tags without `width`/`height` (CLS protection).\n- No render-blocking `<script>` in `<head>`.\n- `web-vitals` test (`npx unlighthouse --site localhost:4321`) shows LCP < 2.5 s.\n```\n\n## Warum diese Regeln\n\n- **Bilder mit expliziten Abmessungen (CLS-Verhinderung)** ist die am häufigsten übersehene Leistungsregel in KI-generiertem Code. Agenten, die `<img src=\"...\">` ohne `width`- und `height`-Attribute schreiben, verursachen ein erneutes Layout der Seite, wenn das Bild geladen wird, was zu CLS-Werten führt, die das Ranking einer Website zerstören können. Die Behebung ist mechanisch – stets Abmessungen angeben – aber Agenten lassen sie aus, wenn es nicht explizit angegeben wird.\n- **Selbst gehostete Schriftarten** eliminieren eine renderblockierende Cross-Origin-Anfrage, die die LCP bei typischen Verbindungen durchgängig um 200–400 ms verzögert. Agenten verwenden standardmäßig aus Gewohnheit Google Fonts `<link>`-Tags – sie sind für die Entwicklung in Ordnung, aber messbar langsamer als selbst gehostete Schriftarten mit `font-display: swap`.\n\n## Geeignet für\n\n- Öffentliche statische Websites, Marketingseiten, Blogs und Dokumentationen, bei denen Core Web Vitals das Suchranking und die Benutzerkonversion direkt beeinflussen.\n\n## Nicht geeignet für\n\n- Interne Dashboards oder authentifizierte Anwendungen, bei denen Benutzer zuverlässige Verbindungen haben und das SEO-Ranking irrelevant ist – die Leistungseinschränkungen sind real, aber die geschäftlichen Auswirkungen sind geringer."
}