#Static routes with dynamic content

4 messages · Page 1 of 1 (latest)

grim shard
#

Hi. Is it possible to have stattic paths that are determined at build-time, but have the actual content of the page rendered on demand?

fossil egretBOT
#

Hi @grim shard. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

Yes, this is possible in Astro! You can mix static (prerendered) and on-demand rendered routes in the same project. However, what you're describing — static paths determined at build time but with content rendered on demand — is a nuanced combination. Let me clarify what Astro supports:

Option 1: Fully Prerendered Static Routes (Build-time paths + build-time content)

Using getStaticPaths(), Astro generates both the paths and the content at build time. This is the default static behavior. [Static SSG Mode]

Option 2: On-Demand Dynamic Routes (Request-time paths + request-time content)

With an adapter and export const prerender = false, routes are matched and rendered entirely at request time — no getStaticPaths() needed or supported. [On-demand Dynamic Routes]

What About Static Paths + On-Demand Content?

The knowledge sources do not describe a hybrid where getStaticPaths() defines the URL paths at build time while the page content itself is deferred to request time. These two concepts are tied together in Astro's model: if you use getStaticPaths(), the page is prerendered (static); if you want on-demand rendering, you skip getStaticPaths() and handle the params at request time.

However, there is a related pattern worth considering:

Server Islands as a Workaround

You can have a prerendered (static) page that contains dynamic, on-demand rendered components using Server Islands. The page shell and routes are determined at build time, but specific components within the page are rendered on demand per request:

#
---
// src/pages/index.astro
import Avatar from '../components/Avatar.astro';
---
<Avatar server:defer>
  <span slot="fallback">Loading...</span>
</Avatar>

This requires an adapter to be installed. [Server Islands]

Summary

Approach Paths Content
Static (default) Build time Build time
On-demand SSR Request time Request time
Static + Server Islands Build time Mix: static shell + on-demand components

If your goal is to have personalized or frequently updated content on pages whose URLs are known ahead of time, Server Islands are likely the best fit.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: