• Astro in South Africa
  • Static and server pages
  • First month free

Astro Static Site: When It Needs a Server and Where to Host It

Learn how an Astro static site works, when it needs a server for forms, logins and live data, and how to choose hosting that runs both.

You built a clean, fast Astro static site for a client. The pages load in a blink, the Lighthouse scores look like exam results you'd frame, and hosting it was as easy as uploading a folder. Then the client asks for a contact form that saves enquiries, and a members-only page. Suddenly, "static" isn't the whole story.

Astro is built for exactly this moment. It starts static, and it can add server features page by page when you need them. (The site you're reading right now runs on Astro, so we've walked this road ourselves.) This guide explains how an Astro static site works, when it needs a server, and how to choose hosting that won't make you move house when your site grows. New to app hosting in general? Our guide to web app hosting covers the basics.

Key Takeaways: Astro Static Sites

  • Astro builds a static site by default. Every page is rendered to HTML at build time and can be served as plain files.
  • It's more than a static site generator. Add an adapter, and any page can be server rendered on demand.
  • Forms that save data, logins, and personalised pages need a server. Everything else can stay static.
  • One line switches a page: export const prerender = false tells Astro to render that page on demand.
  • Choose hosting that runs both, so adding server features never means moving your site. HCode does, from R50 a month.

Is Astro a Static Site Generator?

Yes. Astro is a static site generator by default, and it can also render pages on a server when you need it to.

Out of the box, Astro prerenders your whole site at build time. Every page becomes a finished HTML file, ready to be served as-is. That's what makes Astro such a good fit for blogs, documentation, portfolios, and marketing sites, where most pages look the same for every visitor.

But Astro grew past its static-site-generator roots a while ago. Add an adapter, and it can render chosen pages on demand, handle form submissions with actions, and run API endpoints. So the more accurate answer is that Astro is a static-first web framework: static where it can be, server rendered where it has to be.

How an Astro Static Site Works

An Astro static site is built once, then served as plain files to every visitor.

When you run npm run build, Astro renders each page to HTML and writes the result to a dist folder. That folder holds everything your site needs: HTML, CSS, images, and the small amount of JavaScript your pages actually use. Any host that can serve files can serve it.

The JavaScript part is where Astro earns its speed reputation. Astro uses an "islands" approach: the page ships as plain HTML, and only the interactive pieces, like a search box or an image carousel, load JavaScript. Those islands can be built with React, Vue, Svelte, or plain Astro components. The rest of the page stays as light as a printed brochure.

The result is fast, simple, and cheap to host. The catch is that a static page is the same for everyone, and it can't do anything when a visitor sends it information.

When Your Astro Static Site Needs a Server

Your Astro static site needs a server the moment a page has to react to the person viewing it, or to information they send.

Here are the usual triggers:

  • A form that saves or sends something. A contact form that stores enquiries, a booking request, or a newsletter sign-up handled by your own code.
  • Logins and members-only pages. Anything that checks who the visitor is before showing a page.
  • Personalised content. A dashboard, an account page, or prices that change per customer.
  • Live data. Stock levels, availability, or anything that changes too often to rebuild the whole site.
  • Your own API endpoints. Routes that run code on the server, such as fetching from a database or calling a payment provider with a secret key.

If none of these apply, keep it static. If even one does, that page needs to be server rendered, while the rest of your site can carry on exactly as it is.

Static, Server Rendered, or Both?

With Astro, you don't have to choose one for the whole site. Pages stay static by default, and you switch individual pages to server rendering only where you need it.

It takes two things. First, an adapter, which tells Astro what kind of server will run the on-demand pages. On a Node.js host, that's the official @astrojs/node adapter. Second, one line at the top of each page that should render on demand:

---
export const prerender = false
---

That's it. The rest of your site stays a static site, built ahead of time, and only the pages you mark get rendered by the server when someone visits.

Static (prerendered) pageServer-rendered (on-demand) page
When it's builtOnce, at build timeEach time someone visits
Same for every visitor?YesNo, it can change per visitor
Needs a running server?NoYes, through an adapter
Good forBlog posts, docs, landing pagesForms, logins, dashboards, live data

You may come across two older terms while reading about this. Hybrid rendering was Astro's name for mixing static and on-demand pages; since Astro 5, that's simply how the default static mode works. And output: 'server' flips the default the other way, rendering every page on demand unless you mark it with export const prerender = true. Astro's own advice is to stay with the default static mode unless most of your pages need a server.

One more Astro term worth knowing: server islands, which let a mostly static page load one dynamic component, like a logged-in user's avatar, from the server. They need an adapter too.

Diagram of one Astro site built from one repository with two kinds of page: prerendered pages, such as the home page, blog posts and docs, built once and served as plain files with no server; and on-demand pages, such as a contact form, members area, dashboard and API endpoint, rendered on each visit by a running server through an adapter.

Where to Host an Astro Static Site (and What Happens When It Grows)

A fully static Astro site can live almost anywhere. The real question is where it can live once it needs a server.

For a purely static build, the options are wide. Free static hosts, shared hosting, and object storage can all serve a dist folder. If your site will stay static for good, a simple static host is a perfectly sensible choice.

The trouble starts with the first server-rendered page. Many static hosts can't run your own Node.js server, so adding a contact form or a members area often means one of two things: rebuilding your setup around that host's own adapter and serverless functions, or moving the whole site somewhere else. Neither is fun on a deadline. It's a bit like buying a flat with no room for a second bedroom, then finding out you're expecting.

So when you choose hosting for an Astro static site, ask one extra question: can this host run server-rendered pages from the same repository when I need them? If the answer is yes, your site can grow page by page without a migration. Look for:

  • Support for a static build and a Node.js server, from one repository
  • A database close to your server routes, for forms and accounts
  • Environment variables for secrets, so API keys never reach the browser
  • Easy rollbacks, so a broken release isn't a disaster

Hosting Astro on HCode

HCode is HostAfrica's managed app platform, and it runs both kinds of Astro page from the same repository, so adding server features never means moving host.

  1. Pick a plan. Choose one on the Astro hosting page and order it in the HostAfrica client panel. Plans start at R50 a month, and code HCODEFREE2026 makes your first month free.
  2. Connect your code. Link your GitHub repository or upload a .zip, and add any API keys as environment variables.
  3. Push. HCode detects Astro, runs your build, and serves the result with SSL.
What your Astro site needsOn HCode
A static buildServed as-is, straight from your dist folder
Server-rendered pages, endpoints, and actionsAdd @astrojs/node in standalone mode, and HCode keeps the Node.js server running
A database for forms and accountsManaged PostgreSQL on a private network beside your app, backed up daily
Secrets kept off the pageStored encrypted in the panel; only variables prefixed with PUBLIC_ reach the browser
Safe releasesEvery push rebuilds the site; a failed build leaves the live site as it was, and rollbacks take one click
A domainA free subdomain on the first deploy, then your own domain with automated SSL

Already hosting your Astro site somewhere else? If it uses that host's adapter, swap it for @astrojs/node, connect your repository, copy your environment variables into the panel, and deploy. Your database can come with you from a .sql file or pg_dump archive. Everything runs in South Africa, on one flat price in rand.

Prefer to Run It Yourself?

An Astro site built with the Node adapter is a Node.js app, so you can run it on your own server if you'd rather manage everything yourself. Our guide on how to deploy a Node.js app from GitHub to a VPS walks through the same workflow, and our broader guide to deploying an app from GitHub to a VPS covers the setup from the first SSH login.

FAQs: Astro Static Sites

Is Astro a Static Site Generator?

Yes, by default. Astro prerenders every page to HTML at build time. With an adapter, it can also render chosen pages on demand, so it works as both a static site generator and a server-rendered framework.

Can I Host an Astro Static Site for Free?

A fully static Astro site can be hosted for free on several static hosts, within their limits. Once your site needs server-rendered pages or a database, you'll need hosting that runs a server. HCode has no free tier, but code HCODEFREE2026 gives you your first month free.

Does Astro Support SSR?

Yes. Add an adapter, then mark a page with export const prerender = false to render it on demand (server-side rendering). The rest of your site stays static.

Does Astro Have Incremental Static Regeneration?

Not under that name. Astro's built-in options are prerendering at build time or rendering on demand. For pages that change often, you can render them on demand and cache the response; Astro's documentation covers route caching for this.

Can I Add a Contact Form to a Static Astro Site?

Yes. Make the form's page or endpoint render on demand, and handle the submission with an Astro action or API endpoint. Your host then needs to run a server for that route, while the rest of the site stays static.

How Do I Move an Astro Site to HCode?

Switch your current adapter to @astrojs/node, connect your GitHub repository or upload a .zip, copy your environment variables into the panel, and deploy. A fully static site needs no adapter at all.

Avatar for Ashwin S.

The Author

Ashwin S.

Ashwin is a content specialist at HostAfrica, where he's been crafting clear, authoritative copy since 2021. With a background in digital marketing and a passion for impactful storytelling, he turns complex ideas into trustworthy, engaging content. Ashwin writing helps our audience navigate web hosting and cloud solutions with confidence.

Start Static. Grow Without Moving.

Host your Astro static site on HCode today, and add forms, logins, and live data whenever you're ready, all from the same repository, with PostgreSQL right beside it. One flat price in rand.

Your first month is on us with codeHCODEFREE2026