Back to devlog

We Replaced a Next.js Server with Static Astro and a Caddyfile

Our marketing site kept a Node server holding about 620 MB to serve pages that were already static. What moved into a Caddyfile, what we deleted, and what it cost.

astrocaddynextjsself-hostingi18n
The Retropolis map around the Eiffel Tower at night, with coins to collect and buildings to claim

This is the marketing site of Retropolis, a GPS strategy game: a home page, a wiki, this devlog, an install page, legal pages and a support form, in five languages. Until 19 November 2026 it was a Next.js app running as a standalone Node server on a machine we host ourselves. That day its container held about 620 MB of memory, with a peak at 784 MB.

Later that day the site was plain HTML built by Astro and served by Caddy, and the container read 14.9 MB. This post covers what moved where, with the configuration, and what we gave up.

What the Node server was for

Our ticket named two suspects for the memory: the next/image optimizer, which runs sharp and libvips inside the server process, and a V8 heap with no limit set. Both can be tuned. The next paragraph of the ticket was more useful: every page was already rendered at build time, and the Node runtime existed for four things.

  • A proxy file that picked the visitor's language.
  • An API route that relayed the support form to our Discord bot.
  • The image optimizer.
  • Two .well-known routes for app links.

None of them needs an application server, so each one went to something smaller.

React at build time

We kept our React components. Astro renders them to HTML during the build, and a component without a client directive ships no JavaScript. Page bodies moved out of app/[locale]/…/page.tsx into plain components, each mounted by a thin .astro file under src/pages/[...locale]/. The rest parameter gives us English at unprefixed URLs and the other languages under /fr, /de, /es and /it from one set of files:

export const localeParam = (locale: Locale) => (locale === 'en' ? undefined : locale);

export const localePaths = () =>
    locales.map((locale) => ({ params: { locale: localeParam(locale) }, props: { locale } }));

An undefined rest parameter builds the page at the root. With build.format: 'file' and trailingSlash: 'never', the output is install.html and fr/install.html. The build we shipped that day had 197 HTML files.

Two consequences are easy to miss. First, Astro renders each React component it meets as a separate root, so our locale context no longer reached anything. Every top-level component now goes through a wrapper:

export function localized<P extends object>(Component: ComponentType<P>) {
    function Localized({ locale, ...props }: P & { locale: Locale }) {
        return (
            <LocaleProvider locale={locale} messages={getMessages(locale)}>
                <Component {...(props as P)} />
            </LocaleProvider>
        );
    }
    return Localized;
}

Second, a component rendered this way never runs in the browser: no state, no effects, no onClick. The mobile menu, the language switcher and the store banner became one small script that finds its elements in the static HTML, 1,167 bytes once built. The wiki search filters server-rendered cards that carry their search text in a data-search attribute. The accordion on the legal page went from Radix to native <details> elements sharing a name, which keeps a single item open with no script.

The support form is the only island. It has four steps and image uploads, so it hydrates with client:load.

Language redirects in a Caddyfile

The old proxy sent a visitor on an unprefixed URL to their language: a saved cookie first, the browser's first language otherwise. That is now two matchers:

@savedLocale {
	path_regexp page ^((?:/[^/.]+)*)/?$
	not path /fr /fr/* /de /de/* /es /es/* /it /it/* /guides /guides/*
	header_regexp saved Cookie (?:^|;\s*)retropolis-locale=(fr|de|es|it)(?:;|$)
}
redir @savedLocale /{re.saved.1}{re.page.1}{?query} 302
@browserLocale {
	path_regexp page ^((?:/[^/.]+)*)/?$
	not path /fr /fr/* /de /de/* /es /es/* /it /it/* /guides /guides/*
	not header Cookie *retropolis-locale=*
	header_regexp browser Accept-Language ^\s*(fr|de|es|it)(?:[-_;,\s]|$)
}
redir @browserLocale /{re.browser.1}{re.page.1}{?query} 302
  • The path regexp only matches extensionless paths, so assets, robots.txt and the sitemap never redirect.
  • A saved en cookie matches neither block, because the second matcher refuses any request that carries the cookie. Without that line, a visitor with a French browser who chose English would be sent back to /fr at every visit.
  • Guides exist only in the languages they were written in, so they are excluded.

It is a redirect rather than content negotiation on one URL because of crawlers. Google's documentation says its crawler sends requests without an Accept-Language header, and recommends separate URLs per locale with hreflang annotations. A crawler gets English at the unprefixed URL and finds the other four through hreflang, in the pages and in the generated sitemap.

One caveat: these responses depend on two request headers and we send no Vary for them. That holds only while nothing in front of Caddy caches HTML by URL alone. If we cache pages at the edge one day, this logic has to move there.

The rest of the file is short. try_files {path} {path}.html gives clean URLs. A trailing slash and the old /en/... prefix answer 308. /_astro/* is hashed and gets max-age=31536000, immutable; pages get no Cache-Control header of their own. A handle_errors 404 block rewrites a missing /fr/... path to /fr/404.html, so the error page is translated too.

One line exists because of a file name. Apple's apple-app-site-association has no extension, so a file server cannot guess its type: header /.well-known/* Content-Type application/json.

The runtime stage of the Dockerfile went from a Node image with four COPY lines and a CMD to this:

FROM caddy:2.11.6-alpine
COPY apps/web/Caddyfile /etc/caddy/Caddyfile
COPY --from=build /app/apps/web/dist /srv

The support form posts to the bot

The form used to post to a Next API route, which rate-limited, converted screenshots to base64 and forwarded the ticket to our Discord bot with a shared secret. With no server behind the site, the browser now posts JSON to a public POST /support-ticket on the bot. Three jobs moved there:

  • Validation. Required fields, a length limit per field (5,000 characters for the description), a closed list of issue types, at most three images. Unknown fields are dropped.
  • Rate limiting. Five tickets per IP per ten minutes, counted in memory.
  • CORS. An allowlist of the site's origins, answered on the preflight and on the response.

Nothing equivalent replaced the shared secret. CORS only restrains browsers, and anyone can post to that endpoint with curl. What protects the bot is the validation, the rate limit and a 2 MiB body cap. That cap is why the form shrinks screenshots before sending: 1,600 pixels at most on the long side, re-encoded as JPEG at decreasing quality until the file is under 400 KB.

Images without an optimizer

next/image resized on demand, which let us keep 2 to 3 MB PNG screenshots in the repository. Now public/ is served as is, so a file has to be right when it is committed. Seven screenshots went from 17.9 MB of PNG to 1.4 MB of WebP at the same dimensions. The cover of this post is one of them: 2.1 MB before, 309 KB after, 1170 × 2532 both times. A character portrait went from 1024 to 640 pixels and from 409 KB to 29 KB.

The numbers

Point measurements from 19 November 2026, not a benchmark.

Next.js standaloneAstro + Caddy
Container memory, productionabout 620 MB, peak 784 MB14.9 MB
JavaScript on the home pageabout 600 KBone 1.2 KB module
JavaScript on the support pagenot measuredabout 250 KB uncompressed

The same image read 25 MB in a local test before the deploy. The production figure was taken shortly after it, and we have no long-run curve yet. The 600 KB is what we wrote in the ticket before starting, without a breakdown.

What it cost

  • No client-side navigation. next/link became plain anchors, so every click is a full page load. The home page is 27 KB of HTML and we accept it.
  • Interactivity is a decision. A button that does something needs a script module or a new island. The accordion lost its open and close animation in the move to <details>.
  • Images are manual work. Nothing resizes a 3 MB screenshot for us, and there is no srcset: every visitor gets the same file.
  • Routing is regexes without tests. We serve the build with the same Caddy image and request the URLs that matter. After the deploy we checked status codes, a translated 404, the language and /en redirects, the CORS preflight and the rejection of an empty ticket.
  • A public endpoint on the bot. Its rate limit is one map in one process and forgets on restart.
  • A coupled deploy. The form needed its endpoint to exist, so site and bot went out together. The image build also failed until the design-token package joined the Docker context, which is an allowlist.

This is not a case against Next.js. Our admin console still runs on it, because it has sessions and API routes. The marketing site had none of that left and was keeping a runtime alive for four small jobs.

Another part of the same monorepo is described in Making Our Social Videos in Code with Remotion. The site's own job has not changed: get the game.