Astro Best Practices and When to Choose It
Practical guidelines for structuring Astro projects, and knowing when Astro is — and isn't — the right choice.
3 phút đọc
With the individual pieces covered — components, routing, islands, content collections, rendering modes — this closing lesson is about judgment: how to use them well together, and when Astro isn't actually the right tool for a project.
Default to zero JavaScript, then add it back deliberately
The single most common mistake teams make coming from a React or Next.js background is reaching for client:load out of habit, on every interactive-looking component, "just in case." Every client directive is a deliberate cost — audit which components truly need to run in the browser, and prefer client:visible or client:idle over client:load whenever a component isn't needed the instant the page appears. A page with fifteen client:load islands has quietly rebuilt the JavaScript-heavy page Astro was meant to help you avoid.
Keep islands small and self-contained
An island that needs to share state with another island on the page is a sign the boundary is drawn wrong. Since islands hydrate independently with no shared framework runtime, cross-island communication requires extra plumbing (custom events, a shared store loaded by both) that's easy to get wrong. Where possible, scope each island to a self-contained piece of UI — a single widget, not a whole page section — and pass data down via props rather than reaching for cross-island state.
Use content collections once content has structure
For a handful of static pages, plain .astro files are simpler than setting up a schema. Reach for content collections once you have a genuine collection — multiple entries with the same shape (blog posts, docs pages, changelog entries) — where a schema catches mistakes early and getCollection gives you a typed, queryable list instead of manually gluing filenames together.
Pick output mode per project, not per preference
Don't default to server output out of a vague sense that it's "more powerful." Static output is faster, cheaper to host, and has fewer moving parts — reach for server (or per-page prerender = false) only for the specific pages that need per-request data. Most content sites are static almost everywhere with maybe one or two dynamic pages, not the other way around.
When Astro is the right choice
Astro tends to be a strong fit when:
- The site is content-first: a blog, documentation, marketing pages, a portfolio — where most bytes on the page are prose and images, not application state.
- You want islands of interactivity, not a fully interactive app: a handful of widgets embedded in otherwise static pages.
- Performance and SEO matter more than rich client-side interactivity — fast first paint, minimal JavaScript, real HTML for crawlers with no client-side rendering step required.
- You want to mix or gradually adopt UI frameworks without committing an entire codebase to one.
When to reach for something else
Astro is a weaker fit when the product is an application: a dashboard with constant client-side state changes, a real-time collaborative editor, anything where nearly every pixel on the page needs to react to user interaction continuously. In that world, the overhead Astro saves you (unused JavaScript on static content) doesn't apply — there isn't much static content — and a framework built around a persistent, fully hydrated client-side app, like Next.js or a plain React SPA, fits the problem more naturally.
The underlying question worth asking for any project: what fraction of this page is actually interactive? The closer that fraction is to "almost none," the more Astro's defaults work in your favor; the closer it is to "almost all of it," the less benefit its zero-JS starting point provides.