← Back to Skills

astro-best-practices

active

Analyzes Astro 5 projects (.astro, astro.config.mjs/ts) to identify performance issues, applies 47 optimization rules across 8 prioritized categories (islands architecture, build optimization, content collections, image optimization, component patterns, view transitions, environment config, advanced patterns), and refactors code following partial hydration best practices. Use when building Astro sites, configuring SSG/SSR/hybrid rendering, implementing islands with client:* directives, setting up content collections, or optimizing images and assets. Do NOT use for non-Astro frameworks like Next.js, Nuxt, or SvelteKit.

Owner: tsamantanis Category: frontend Version: 1.0.0 Tokens: ~42k
astroperformanceislands-architecturessgssrcontent-collectionsimage-optimizationastro-5
92

Quality Score Breakdown

Structure (15%) 18/18
Show checks (11)
  • SKILL.md exists with exact casing 3/3
  • Valid YAML frontmatter 3/3
  • No unexpected frontmatter keys 1/1
  • Name field valid (kebab-case) 2/2
  • Name matches folder name 1/1
  • Description field present 2/2
  • No angle brackets in frontmatter 1/1
  • Folder name is kebab-case 1/1
  • No README.md inside skill folder 1/1
  • Test directory with test-cases.yml exists 2/2
  • Status 'active' is valid 1/1
Description (20%) 20/22
Show checks (7)
  • Contains action verbs: analyzes 2/4
  • Contains trigger indicators: use when, use for 5/5
  • Description is specific and actionable 4/4
  • File types mentioned in description 3/3
  • Description length: 625/1024 chars 2/2
  • Has negative triggers (scope boundaries) 2/2
  • Owner/author specified in metadata 2/2
Instructions (25%) 22/28
Show checks (8)
  • Skill body has content 3/3
  • Has step/section structure 4/4
  • Includes examples 5/5
  • Includes error handling 4/4
  • Consider moving detailed docs to references/ for better token efficiency 0/4
  • Instructions could be more actionable — use 'Run X', 'Call Y', 'Check Z' 1/3
  • Word count: 774/5000 2/2
  • All referenced paths exist 3/3
Test Coverage (25%) 29/29
Show checks (10)
  • test-cases.yml exists and parses 3/3
  • 8 should-trigger tests ✓ 4/4
  • 4 should-not-trigger tests ✓ 3/3
  • 7 functional tests ✓ 5/5
  • 2 negative tests ✓ 3/3
  • 3 edge case tests ✓ 3/3
  • Performance baseline documented 2/2
  • All functional tests have ≥2 assertions 2/2
  • All trigger phrases are diverse 2/2
  • All assertions are specific 2/2
Security (15%) 14/15
Show checks (5)
  • No secrets detected 5/5
  • No injection vectors in frontmatter 3/3
  • Name is not reserved 3/3
  • No suspicious code patterns 2/2
  • 104 external URLs found — verify they're necessary: https://docs.astro.build/en/concepts/islands/, https://docs.astro.build/en/guides/server-side-rendering/, https://docs.astro.build/en/guides/content-collections/ 1/2

Suggestions

  • Move detailed reference material to references/ and link from SKILL.md

Test Coverage

8
Should Trigger
4
Should Not Trigger
7
Functional
2
Negative
3
Edge Cases
Yes
LLM Evals

Astro Best Practices Skill

This skill provides comprehensive guidance on Astro 5 best practices for building high-performance, production-ready web applications.

When to Invoke

Activate this skill automatically when:

  • Working with .astro files or Astro components
  • Configuring astro.config.mjs or astro.config.ts
  • Implementing islands architecture with client:* directives
  • Setting up content collections with schemas
  • Optimizing images using Astro’s Image component
  • Configuring SSG/SSR/hybrid rendering strategies
  • Implementing view transitions
  • Working with astro:env or environment variables
  • Setting up middleware or API routes
  • Discussing performance optimization in Astro projects

Quick Reference

Performance Impact Categories

Impact LevelWhen to AddressExample Consequences
CRITICALBefore production deploy80%+ JS bloat, 10x cost increase, failed Core Web Vitals
HIGHDuring implementation2-3s slower LCP, 3.6x build time, type errors in production
MEDIUM-HIGHCode review phaseBundle size issues, maintainability problems
MEDIUMNice to haveUX improvements, better DX
LOW-MEDIUMAdvanced optimizationEdge performance, advanced patterns

Section Overview

SectionRulesPriorityKey Focus
1. Islands & Hydration8CRITICALPartial hydration, client directives, JS bundle optimization
2. Build Optimization7CRITICALSSG vs SSR, hybrid rendering, build performance
3. Content & Data Loading7HIGHContent collections, schemas, data fetching patterns
4. Image & Asset Optimization6HIGHLCP optimization, responsive images, asset strategy
5. Component Patterns6MEDIUM-HIGH.astro vs framework components, composition
6. View Transitions5MEDIUMSPA-like navigation, animation performance
7. Environment & Middleware5MEDIUMType-safe env vars, middleware patterns
8. Advanced Patterns3LOW-MEDIUMStreaming SSR, edge middleware, advanced optimization

Critical Anti-Patterns to Avoid

These are the most common and impactful mistakes in Astro projects:

  1. Using client:load everywhere - Eliminates all benefits of islands architecture (80%+ JS bloat)
  2. Using SSR for static content - 10x higher hosting costs and slower response times
  3. Skipping content collection schemas - Runtime errors and type safety issues in production
  4. Not using the Image component - 2x slower LCP (3.2s → 1.6s typical improvement)
  5. Wrapping entire layouts as islands - Creates massive hydration overhead
  6. Client-side data fetching in .astro files - Breaks the build-time architecture model
  7. Using client:only unnecessarily - Kills SEO and initial page render performance

Rule Categories

1. Islands & Hydration (CRITICAL)

Focus on partial hydration and JavaScript optimization. Incorrect usage can bloat bundles by 80%+ and eliminate Astro’s core performance benefits.

2. Build Optimization (CRITICAL)

SSG vs SSR decisions, hybrid rendering, and build performance. Wrong choices can lead to 10x higher hosting costs and significantly slower response times.

3. Content & Data Loading (HIGH)

Content collections, type safety with Zod schemas, and the Content Layer API. Proper patterns prevent runtime errors and enable 3.6x faster builds.

4. Image & Asset Optimization (HIGH)

Image component usage, responsive images, and asset strategy. Proper optimization typically improves LCP from 3.2s to 1.6s.

5. Component Patterns (MEDIUM-HIGH)

When to use .astro components vs framework components, composition patterns, and type safety strategies.

6. View Transitions (MEDIUM)

Implementing SPA-like navigation with minimal JavaScript, state persistence, and animation performance considerations.

7. Environment & Middleware (MEDIUM)

Type-safe environment variables with astro:env, middleware patterns, and security best practices.

8. Advanced Patterns (LOW-MEDIUM)

Streaming SSR, server islands, edge middleware, and advanced optimization techniques for high-traffic applications.

Integration with Claude Code

This skill is automatically available when working with Astro projects. To explicitly invoke:

Use astro-best-practices skill to review this code

Or reference specific sections:

Check islands hydration patterns against astro-best-practices

Performance Metrics Reference

Common improvements when following these best practices:

  • JavaScript Bundle: 80%+ reduction with proper island usage
  • LCP (Largest Contentful Paint): 3.2s → 1.6s with Image component
  • Build Speed: 35 → 127 pages/second with optimization
  • Hosting Costs: 10x reduction using SSG over SSR for static content
  • Remote Data Fetching: 3.6x faster with Content Layer caching
  • TTFB: 200ms → 50ms with proper SSG configuration

Reference Documentation

All rules link to official Astro 5 documentation:

For complete rule details, see AGENTS.md in this directory.