Astro Quickstart
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.
Server-side rendering flow
User request
The browser sends an HTTP request
Server
Receives the request
Database
Query the data
Server
Generates the HTML
Return the HTML
The browser renders the page
Characteristics
- ✅ SEO friendly: the HTML contains the complete content
- ⚠️ Lower performance: every request has to reach the database
- ⚠️ Heavy server load: the HTML has to be generated on the fly
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.
Static HTML + API flow
User request
The browser sends an HTTP request
Return the static HTML
nginx returns the HTML file directly
Execute the JavaScript
The browser runs the JS code
Backend API
Handle the API request
Update the page
JavaScript updates the DOM
Characteristics
- ✅ Good performance: static files are returned directly by nginx
- ⚠️ Not SEO friendly: the initial HTML contains no data content
- ⚠️ Two requests are needed: HTML + API
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 loading flow
User request
The browser sends an HTTP request
Return an empty HTML
Only the basic structure, no content
Download the JavaScript
Framework code + application code
Execute the JavaScript
The browser parses and runs the code
The page is rendered
The user sees the complete page
Characteristics
- ✅ Highly interactive: complex client-side interactions are possible
- ⚠️ Slow first load: a large amount of JS code has to be downloaded
- ⚠️ Not SEO friendly: the initial HTML is empty
- ⚠️ High runtime cost: every user has to render the page in the browser
If everyone is rendering anyway, why not render on the server and send HTML directly?
Do everything you can at build time; keep only essential interactive logic for runtime.
Astro build-time rendering
Fetch data at build time
Pull data from a database or API
Generate static HTML
Pre-render every page
User request
The browser sends an HTTP request
Return the static HTML
It contains the complete content
The page shows immediately
Fast to load, SEO friendly
Advantages
- ✅ SEO friendly: the HTML contains the complete content
- ✅ Excellent performance: static files are returned directly, with no server-side processing
- ✅ Fast loading: only the necessary JavaScript is loaded
- ✅ Low server load: no HTML has to be generated on the fly
- ✅ Highly scalable: CDN acceleration and worldwide distribution
“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.
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).
- 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.
