Building Production-Ready Websites with Astro and Cloudflare Pages
A practical guide to deploying fast, maintainable static sites using Astro's island architecture and Cloudflare's global edge network.
Modern static site generators have come a long way. Astro has emerged as one of the most compelling frameworks for building content-heavy sites that need to be fast, maintainable, and SEO-friendly.
In this post, we cover the key decisions we make when deploying Astro to Cloudflare Pages for production workloads.
Why Astro?
Astro takes a different approach to most JavaScript frameworks. By default, it ships zero JavaScript to the browser. Pages are rendered to pure HTML at build time. If you need interactivity, you opt-in per component using directives like client:load or client:visible.
This results in:
- Extremely fast page loads (no hydration overhead)
- Excellent Core Web Vitals scores out of the box
- Lower bandwidth costs for your users
- Better SEO via complete server-rendered HTML
Project structure
We favour a clear, conventional structure:
src/
components/ # Reusable UI
layouts/ # Page wrappers
pages/ # Route definitions
content/ # Markdown / MDX
styles/ # Global CSS
Content lives in src/content/ and is typed using Astro’s Content Collections API. This means every blog post and page has a validated schema — breaking changes are caught at build time, not runtime.
Deployment to Cloudflare Pages
Cloudflare Pages is our preferred host for Astro projects because:
- Global edge delivery — pages are served from 300+ locations worldwide
- Free tier is genuinely generous — 500 builds/month, unlimited requests
- Pages Functions — serverless JavaScript at the edge for form handling, APIs
- Automatic HTTPS and HTTP/2 out of the box
The build configuration is simple:
- Build command:
npm run build - Output directory:
dist - Node version: 20
Performance tips
To consistently hit Lighthouse 98+:
- Use
loading="lazy"on all below-fold images - Preconnect to external font origins
- Inline critical CSS (Astro handles this automatically when using
<style>in components) - Use
<link rel="preload">for hero images - Avoid importing large JavaScript libraries — use native browser APIs where possible
Conclusion
The Astro + Cloudflare Pages combination is hard to beat for content sites and marketing pages. You get the developer experience of a modern framework with the performance characteristics of hand-crafted HTML.
If you are building a new site and performance matters, start here.