Astro Best Practices Audit


As developers, we often build sites without stepping back to evaluate how well they align with best practices. Today, I’m conducting a comprehensive audit of this Astro site to assess its adherence to modern static site development patterns.

Overall Score: A- (Excellent)

The site demonstrates excellent mastery of Astro fundamentals with room for optimization in modern image handling and content management patterns.

✅ What We’re Doing Right

1. Content Collections - Grade: A+

Our implementation showcases exemplary use of Astro’s content collections:

  • 8 well-defined collections: post, note, privateNote, series, research, projects, writing, pages
  • Type-safe schemas using Zod validation throughout
  • Modern Astro v5 patterns with glob loaders
  • Smart data transformation with utilities like removeDupsAndLowerCase for tags

Example from our research collection:

paperDate: z.string().regex(/^\d{4}$/, "Must be 4-digit year"),
authors: z.string(),
featured: z.boolean().default(false),

2. Static-First Architecture - Grade: A

We’ve committed to a 100% static generation approach:

  • No client-side data fetching - everything rendered at build time
  • Pre-rendered routes with proper getStaticPaths implementation
  • Smart pagination for blog posts maintaining performance
  • Build-time content processing for optimal delivery

3. TypeScript Integration - Grade: A

Type safety is woven throughout the codebase:

// Central type definitions
export interface SiteConfig {
  author: string;
  title: string;
  description: string;
  //... comprehensive typing
}
 
// Content type safety
type Props = InferGetStaticPropsType<typeof getStaticPaths>;

4. SEO & Meta Tags - Grade: A+

Our SEO implementation goes beyond basics:

  • Complete Open Graph tags with dynamic images
  • Dynamic OG images generated with Satori
  • RSS feeds for posts and notes
  • Automatic sitemap generation
  • Structured data for article schema

5. Component Architecture - Grade: A-

The component structure follows clean architecture principles:

src/components/
├── blog/ # Blog-specific components
├── layout/ # Layout components
├── note/ # Note components
└── typography/ # Typography system

⚠️ Areas for Improvement

1. Image Optimization - Current: C

We’re using native HTML images instead of Astro’s optimized Image component:

<!--Current approach-->
<img src={photo.src} alt={photo.alt} loading="lazy" />
 
<!--Best practice-->---import { Image } from 'astro:assets';---<Image src={profilePhoto} alt={photo.alt} width={400} height={400} />

2. Content Editing Pattern - Current: B-

Hero content is hardcoded in templates. A better approach would use content collections:

# src/content/pages/home.yaml
hero:
  title: "Nathan Lane"
  description: "Economist and Data Scientist..."
  buttons:
  - text: "Read Blog"
  href: "/posts/"

3. Critical Path Optimization - Current: B

We’re missing font preloading for our Newsreader variable font:

<!--Should add to BaseHead.astro-->
<link rel="preload"
  href="/fonts/newsreader-variable.woff2"
  as="font"
  type="font/woff2"
  crossorigin>

4. Component Props Validation - Current: B-

Many components lack explicit TypeScript interfaces:

export interface Props {
  title: string;
  description?: string;
  featured?: boolean;
}
const { title, description, featured = false } = Astro.props;---```
 
## 📊 Benchmark Comparison
 
| Feature | Our Site | Astro Best Practice | Status |
|---------|----------|-------------------|---------|
| Content Collections | ✅ 8 collections | ✅ Use for all content | Exceeds |
| TypeScript | ✅ Extensive | ✅ Recommended | Matches |
| Image Optimization | ❌ Native img | ✅ Astro Image | Needs Work |
| Performance | ✅ 100/100 likely | ✅ 90+ Lighthouse | Matches |
| SEO | ✅ Complete | ✅ Meta + OG + Schema | Exceeds |
| Component Props | ⚠️ Partial | ✅ Full typing | Needs Work |
 
## 🏆 What Sets This Site Apart
 
1. **Sophisticated typography system** with Newsreader variable font and optical sizing
2. **6px baseline grid** - unusual but meticulously implemented
3. **Comprehensive content collections** - more structured than most sites
4. **Excellent dark mode** with nuanced color adjustments
5. **Strong TypeScript usage** providing confidence in refactoring
 
## 📋 Implementation Roadmap
 
Based on this audit, here's our priority list:
 
1. **Implement Astro's Image component** (~2 hours)
  - Automatic format conversion (WebP/AVIF)
  - Responsive sizing
  - Lazy loading with native browser support
 
2. **Create content collection for homepage** (~1 hour)
  - Move hero content to YAML
  - Enable non-developer editing
  - Maintain type safety
 
3. **Add font preloading** (~15 minutes)
  - Reduce CLS (Cumulative Layout Shift)
  - Improve perceived performance
  - Critical for our typography-focused design
 
4. **Add prop types to components** (~2 hours)
  - Start with frequently used components
  - Improve IDE experience
  - Catch errors at build time
 
## Conclusion
 
This audit reveals a site that excels in fundamental Astro patterns while having clear opportunities for optimization. The architecture is solid, the content management is sophisticated, and the performance baseline is strong.
 
The improvements identified are refinements rather than fundamental flaws - a testament to the initial implementation quality. By addressing these areas, we can elevate an already excellent site to exemplary status.
 
Next up: implementing these improvements systematically, starting with image optimization.