🔥 All-Access Pass — $199 USD (Regular $499) · Unlock all 2,836 Astro themes ➔
komal.nakrani
Get All-Access Pass ($199)
ThemesCategoriesDocsBlogTips & TricksPricingGet All-Access Pass ($199)
Comparisons••By Komal Nakrani

Next.js Static Export vs Astro for Static Sites

Next.js static export (output: 'export') vs Astro: what each builds, which features stop working, how images and JavaScript differ, and which suits a static site.

#Astro#Next.js#Static Export#Static Site#Comparison

Next.js static export (output: 'export' in next.config) builds a Next.js app into plain HTML, CSS and JavaScript files in an out/ folder that any static host can serve. It works well, but it turns off every feature that needs a server, and each page still loads the React runtime. Astro is static by default, optimises images at build time, and ships no JavaScript unless a component asks for it, so for a purely static content site Astro is usually the simpler fit. If your team is already deep in Next.js, static export is a reasonable way to host it cheaply.

This comparison covers what static export does, what it gives up, and how Astro’s static output differs.

Key Takeaways

  • Enable static export with output: 'export'; next build writes the site to out/.
  • Static export drops server features: middleware, rewrites, redirects and headers in config, Server Actions, ISR, cookies, and the default image optimiser.
  • Dynamic routes need generateStaticParams() so every path is known at build time.
  • Exported pages still hydrate React on the client and include React Server Component payload files for navigation.
  • Astro’s static build has image optimisation built in and ships zero JavaScript by default.

How Next.js static export works

Set the output mode in your config:

// next.config.mjs
/** @type {import('next').NextConfig} */
const nextConfig = {
  output: 'export',
  trailingSlash: true,
  images: { unoptimized: true },
};

export default nextConfig;

Run next build and Next.js pre-renders every route to HTML in out/. With trailingSlash: true, /about becomes out/about/index.html, which most static hosts serve without extra rules. The separate next export command was removed in Next.js 14; the config option replaced it. The official Next.js static exports guide lists every supported and unsupported feature.

Dynamic routes must list their paths at build time:

// app/blog/[slug]/page.tsx
import { getAllPosts, getPost } from '@/lib/posts';

export async function generateStaticParams() {
  const posts = await getAllPosts();
  return posts.map((post) => ({ slug: post.slug }));
}

export default async function Post({ params }: { params: Promise<{ slug: string }> }) {
  const { slug } = await params;
  const post = await getPost(slug);
  return <article><h1>{post.title}</h1></article>;
}

Server Components still run, but only at build time. Their output is baked into HTML plus the payload files the client router uses.

What stops working in a static export

Anything that needs a server at request time isn’t available:

Feature In static export
Middleware Not supported
redirects, rewrites, headers in next.config Not supported, use host rules
Server Actions Not supported
Incremental Static Regeneration Not supported
Route Handlers reading the request Only static GET handlers
cookies(), headers() Not supported
Default next/image optimisation Needs unoptimized: true or a custom loader
Dynamic routes without generateStaticParams() Build error
Draft Mode Not supported

If you hit one of these, next build fails with a message naming the feature. Most teams work around the list with host features (Netlify or Cloudflare redirect files, edge functions) or by calling separate APIs from the client.

What Astro’s static build does differently

Astro’s default output is 'static', so no config change is needed. Dynamic routes use getStaticPaths(), the same idea as generateStaticParams():

---
// src/pages/blog/[id].astro
import { getCollection, render } from 'astro:content';
import BaseLayout from '../../layouts/BaseLayout.astro';

export async function getStaticPaths() {
  const posts = await getCollection('blog');
  return posts.map((post) => ({ params: { id: post.id }, props: { post } }));
}

const { post } = Astro.props;
const { Content } = await render(post);
---
<BaseLayout title={post.data.title} description={post.data.description}>
  <article>
    <h1>{post.data.title}</h1>
    <Content />
  </article>
</BaseLayout>

Three differences matter in practice:

  1. Images are optimised at build time. <Image /> from astro:assets resizes and converts local images to WebP during the build, with width and height set to prevent layout shift. A static Next.js export has to skip optimisation or use an external image service.
  2. No JavaScript by default. The page above ships zero client JavaScript. A Next.js export hydrates React on every page, even one that is only text.
  3. Redirects still work. redirects in astro.config.mjs produce small HTML redirect pages in a static build, and several adapters turn them into host redirect rules. Next.js config redirects are ignored in a static export.

Both stop at the same boundary: no server, no per-request logic. In Astro, crossing it is a per-route change (export const prerender = false plus an adapter) while the rest of the site stays static. The hybrid rendering tip shows how.

JavaScript and page weight

A static Next.js page includes the React runtime, the Next.js client router and the page’s client components, and it loads the RSC payload for navigation. That gives smooth client-side transitions and prefetching between pages, which is a real benefit for app-like sites.

An Astro page includes only the JavaScript for components marked with client:*. On a blog post or a landing page that can be nothing at all. Astro offers prefetching through the prefetch config option and animated navigation through <ClientRouter />, both opt-in.

For content sites, Astro’s approach usually means smaller pages and less main-thread work on mobile. For interactive sites where most components are client components anyway, the gap narrows.

Developer experience

Next.js static export lets a React team keep App Router conventions, layouts, next/link, and the whole React ecosystem. Moving the same project to a server host later is mostly a config change back.

Astro uses .astro components for pages and layouts (HTML with a script fence) and accepts React components as islands. Content collections give typed Markdown and MDX with schema validation, which Next.js leaves to libraries. Teams new to Astro typically pick it up quickly because a .astro file is mostly HTML. The Astro vs Next.js comparison covers the frameworks more broadly, including server features.

Choose Next.js static export or Astro

Choose Next.js static export if:

  • The project is already a Next.js app and you want cheap static hosting.
  • Most of the UI is interactive React that would hydrate anyway.
  • You may move to a Node.js or serverless host later and want to keep the same codebase.

Choose Astro if:

  • The site is mainly content: marketing, blog, docs, portfolio.
  • You want build-time image optimisation without an external service.
  • You want pages with no JavaScript unless a component needs it.
  • You want to add a few server routes later without making the whole site dynamic.

If you’re starting a new static site rather than exporting an existing app, starting from an Astro theme removes most of the setup. All Komal Nakrani themes build to a static dist/ folder you can deploy to any host covered in the static deployment docs.

Migrating a static-exported Next.js site to Astro

  1. Run npx astro add react so existing components work.
  2. Map each app/**/page.tsx to src/pages/**.astro; layouts become Astro layout components.
  3. Swap generateStaticParams() for getStaticPaths() and move Markdown into a content collection.
  4. Replace next/link with <a>, and next/image with <Image /> from astro:assets.
  5. Add client:* only to components that need interactivity.

The Next.js migration guide in the Astro docs has more detail.

FAQ

How do I enable static export in Next.js?

Set output: 'export' in next.config.js or next.config.mjs, then run next build. The static site is written to the out/ folder. The old next export command was removed in Next.js 14.

Does next/image work with static export?

Not with the default loader, because it optimises images on a server. Set images: { unoptimized: true } to serve images as-is, or configure a custom loader that points to an image CDN.

Can I use API routes with Next.js static export?

Only Route Handlers that return static data on GET can be exported, since they run once at build time. Handlers that read the request, cookies or headers need a server, as do Server Actions.

Is a Next.js static export faster than Astro?

For first load on content pages, Astro is usually lighter because it ships no React runtime unless a component needs it. A Next.js export can feel faster on later navigation thanks to client-side routing and prefetching.

Do redirects work in a Next.js static export?

No. redirects, rewrites and headers in next.config need the Next.js server. Use your host’s redirect rules instead, such as a _redirects file on Netlify or Cloudflare Pages.