Astro Quickstart
Astro in one line: generate static HTML at build time and ship only the JS needed for interaction at runtime—fast, SEO-friendly, and simple to deploy.
Scenario 1
Build a page that shows a number stored in a database.
Option 1
Run a server (any common server-side language). On every request, fetch the number from the database and render HTML to return to the user.
SEO-friendly, but every request hits the DB, so it’s slower.
服务端渲染流程
- ✅ SEO友好:HTML中包含完整内容
- ⚠️ 性能较低:每次请求都需要访问数据库
- ⚠️ 服务器压力大:需要实时生成HTML
Option 2
Let Nginx return a static HTML shell; the page fetches the number from an API via JavaScript and updates the content.
Fast, but not SEO-friendly because the initial HTML has no number.
静态HTML + API流程
- ✅ 性能较高:静态文件由nginx直接返回
- ⚠️ SEO不友好:初始HTML中没有数据内容
- ⚠️ 需要两次请求:HTML + API
Scenario 2
A highly interactive site with many pages.
Common approach
Use a SPA with Vue/React, handling all pages and interactions on the client.
First load returns an empty HTML plus a large JS bundle; the browser downloads/executes to render and handle interactions.
Supports rich interactivity, but first load is heavy and SEO suffers. Every user downloads the JS and renders in the browser—expensive.
SPA加载流程
- ✅ 交互性强:可以实现复杂的客户端交互
- ⚠️ 首次加载时间长:需要下载大量JS代码
- ⚠️ SEO不友好:初始HTML为空
- ⚠️ 性能开销大:每个用户都要在浏览器中渲染
If everyone is rendering anyway, why not render on the server and send HTML directly?
The ideal approach
Do everything you can at build time; keep only essential interactive logic for runtime.
Astro 构建时渲染
- ✅ SEO友好:HTML中包含完整内容
- ✅ 性能极佳:静态文件直接返回,无需服务器处理
- ✅ 加载速度快:只加载必要的JavaScript
- ✅ 服务器压力小:无需实时生成HTML
- ✅ 可扩展性强:CDN加速,全球分发
Astro’s philosophy
“Content-first, build-time rendering.”
- Default output is static HTML; no JS on first paint, great SEO.
- Only truly interactive components hydrate on demand (partial hydration/islands).
- Mix Vue/React/Svelte/Preact islands on the same page.
Quick start
pnpm create astro@latest(or npm/yarn).- Pick a template and install dependencies.
- Dev:
pnpm dev, then open the shown URL. - Build:
pnpm buildoutputs todist/for static hosting (e.g., Cloudflare Pages).
When to use Astro
- Content/docs/blog/marketing pages aiming for fast first paint and strong SEO.
- Multi-framework pages that mix several component libraries.
- You can still do SSR/API routes, but default to static and minimize dynamic parts.