🌐 Web Development

Astro

Astro

A content-focused web framework. Zero JS by default. Islands architecture.

πŸ“– Detailed Explanation

Astro is an all-in-one web framework for content-focused websites. It was developed by Astro Technology, founded by Fred K. Schott in 2021, and with the motto "Ship Less JavaScript," it sends only the minimum client-side JavaScript. By default it strips all JavaScript at build time and adopts an islands architecture that adds it selectively only where needed.

Astro's core philosophy is "Content First." It is optimized for content-centered sites such as blogs, documentation sites, and marketing pages, and supports Markdown and MDX out of the box. Built-in features such as image optimization, RSS feeds, and sitemap generation let you build content sites quickly.

Astro's most distinctive feature is framework agnosticism. You can mix React, Vue, Svelte, and Solid components in the same project. Components are converted to HTML at build time, and only the parts that need interactivity are hydrated using client:* directives.

In practice, Astro easily achieves a Lighthouse score of 100 and is popular for content sites where SEO matters. As of 2023 it recorded 400,000 weekly npm downloads, and it integrates with all major hosting platforms such as Vercel and Cloudflare Pages.

πŸ’» Code Example

---
// src/pages/blog/[slug].astro
// Astro μ»΄ν¬λ„ŒνŠΈ - ν”„λ‘ νŠΈλ§€ν„°μ—μ„œ μ„œλ²„ 둜직 μ‹€ν–‰
import Layout from '../../layouts/Layout.astro';
import { getCollection } from 'astro:content';

export async function getStaticPaths() {
  const posts = await getCollection('blog');
  return posts.map(post => ({
    params: { slug: post.slug },
    props: { post }
  }));
}

const { post } = Astro.props;
const { Content } = await post.render();
---

<Layout title={post.data.title}>
  <article>
    <h1>{post.data.title}</h1>
    <time>{post.data.date.toLocaleDateString('ko')}</time>

    <!-- Markdown μ½˜ν…μΈ  λ Œλ”λ§ -->
    <Content />

    <!-- React μ»΄ν¬λ„ŒνŠΈ - 클릭 μ‹œμ—λ§Œ λ‘œλ“œ -->
    <LikeButton client:visible postId={post.slug} />
  </article>
</Layout>

<!-- μΈν„°λž™ν‹°λΈŒ μ•„μΌλžœλ“œ 예제 -->
<Counter client:load />        <!-- νŽ˜μ΄μ§€ λ‘œλ“œ μ‹œ μ¦‰μ‹œ ν•˜μ΄λ“œλ ˆμ΄μ…˜ -->
<Comments client:visible />    <!-- λ·°ν¬νŠΈμ— 보일 λ•Œ λ‘œλ“œ -->
<Analytics client:idle />      <!-- λΈŒλΌμš°μ € idle μƒνƒœμΌ λ•Œ λ‘œλ“œ -->

πŸ—£οΈ Say It Like This in Practice

πŸ’¬ In a Meeting
"I think we should build this docs site with Astro. We can start with 0KB of JavaScript, get a Lighthouse score of 100, and reuse our existing React components as they are. The content collections feature also makes managing MDX easy."
πŸ’¬ In an Interview
"Astro uses Islands Architecture. Most of the page is rendered as static HTML, and only components that need interactivity are selectively hydrated with directives like client:visible. This can cut the JavaScript bundle size by more than 90%."
πŸ’¬ In a code review
"I think we should change this component from client:load to client:visible. It's in an area you only see after scrolling, so hydrating it when it enters the viewport will make the initial load faster."

Take a mock interview on this topic β†’ WIA SOOM AI Interview Β· Start for free

⚠️ Common Mistakes & Cautions

❌
Using it for highly interactive apps

Astro is for content sites. For apps such as SaaS dashboards and real-time collaboration tools, Next.js or SvelteKit is a better fit.

❌
Using client:load on every component

This negates Astro's advantages. Choose an appropriate directive such as client:visible or client:idle.

βœ…
The right pattern

Build content with Astro components and separate interactivity into React/Vue islands. Also use the View Transitions API to implement smooth page transitions.

πŸ”— Related Terms

πŸ“š Learn More