Why static beats dynamic for document sites

A server, a database, and a runtime to return a page that hasn't changed in three weeks. The case for shipping cacheable HTML, and the pages that earn live computation.


The default architecture for a new website can be wildly over-built. You reach for a server because the tutorial had one, a database because the framework assumed it, and a runtime that has to query, render, and serialize on every uncached request, all to return a page that hasn’t changed in three weeks. The machinery is real. The bill is real. The failure modes are real. The content is static.

A blog post, a marketing page, a changelog, a docs page. These are documents. When the output is the same for everyone and changes rarely, I want to assemble it when it changes and serve the result. Computing it again for every reader is work the reader didn’t ask for.

What static actually buys you

A static page is HTML, CSS, and whatever JavaScript the page needs, generated ahead of requests and delivered as files. Put those files behind a CDN and a cache hit can skip the application server entirely. The substitution sounds small. The consequences aren’t. You move work from every uncached read to publication.

For that public read path, there’s no database connection to exhaust and no N+1 query hiding behind the page. The database might still feed the build. The editor might still need a server. But a reader opening an already published article doesn’t need either one to answer.

// Illustrative uncached request-time rendering
app.get("/post/:slug", async (req, res) => {
  const post = await db.posts.findBySlug(req.params.slug);
  const html = await render(layout, post);
  res.send(html);
});

// Illustrative build-time rendering
for (const post of await db.posts.all()) {
  const html = await render(layout, post);
  await writeFile(`dist/post/${post.slug}.html`, html);
}

The first version repeats the query and render for each request that reaches it. The second does that work during a build. A dynamic route can also cache its output; once it does, the interesting question is how often that cache misses and what a miss costs.

Requests go through an edge cache. Only R times one minus the hit fraction reaches the origin. At 1000 requests per second, a 95 percent hit rate and 20 milliseconds of render CPU imply one average CPU core.

Origin work follows the cache-miss stream. Static files avoid that rendering work; personalized endpoints still need their own runtime and cache policy.

Open full size Scroll horizontally to read the diagram on a small screen.

The miss stream sets the origin-work budget. If traffic is R requests per second and the edge serves a fraction h without origin access, roughly R × (1 − h) requests per second reach the origin. At 1,000 requests per second and a 95% hit rate, that’s 50 origin requests per second. Assume each dynamic render takes 20 milliseconds of CPU: the average render demand is one CPU core, before database work and capacity headroom. Those are example inputs, not measurements of this site.

Static delivery removes that particular render cost. It doesn’t make the network disappear. A cold edge still fetches a file, bandwidth still gets consumed, and a huge image or a pile of JavaScript can still ruin the page. HTML time to first byte, largest contentful paint, and browser work measure different costs. A fast file can contain a slow website.

The economics nobody mentions

A process kept ready for requests costs money while it waits. So do its database, backups, and operational attention. Static files can avoid that idle application capacity for public pages. That’s a useful saving, especially for a site that gets edited occasionally and read repeatedly.

It isn’t a promise of a flat bill. Requests, bandwidth, artifact storage, builds, and cache invalidations can all be charged. A dynamic service can scale to zero or sit behind the same CDN. Free tiers are pricing policies, and I wouldn’t build an architectural argument on one staying free forever.

The comparison is work per edit against work per read. If M edits each rebuild N pages, a naive build does work proportional to M × N. A large site publishing every few seconds can make that expensive. Incremental builds or a few on-demand routes may earn their complexity. A small site rebuilding after an occasional edit usually has a much easier trade to make.

The estimate needs bytes per visit, build frequency, cache misses, and actual provider rates. “Static” describes when output is produced. It isn’t a coupon code.

A cache needs rules

A file sitting at the edge needs an answer to a simple question: when is it allowed to be old?

Content-hashed assets can have long cache lifetimes. Change the bytes, change the URL. HTML needs a publication policy, because its URL usually stays the same when the document changes. Private data needs its own treatment.

# Separate example responses; don't combine these headers.

# Content-hashed public asset
Cache-Control: public, max-age=31536000, immutable

# Public HTML: store it, but validate before reuse
Cache-Control: public, no-cache
ETag: "article-build-42"

# Sensitive account response
Cache-Control: no-store

no-cache doesn’t mean “never store.” It means the stored response needs validation before reuse. An unchanged representation can return 304 without transferring the body. That validation can still reach the origin. A fresh cache hit that avoids the origin is a different path.

no-store tells caches not to store the response. It doesn’t authorize a request or claw back bytes already sent to a browser. Cookies, authorization headers, cache keys, and any CDN-specific policy still need to agree. I don’t put personalized HTML in a shared public cache and hope Vary will rescue it.

Publishing is part of the architecture

A static page doesn’t update because a date changed in a Markdown file. Something has to build the new output and put it where readers can reach it.

That release needs to be complete. Uploading new HTML before its assets gives readers broken references. Deleting old assets while cached HTML still points to them breaks yesterday’s release too. A complete versioned release lets the serving pointer switch only after its files are ready:

content snapshot
  -> build HTML and assets together
  -> verify the release manifest
  -> make the complete release available
  -> switch the serving pointer
  -> refresh HTML caches

Old content-hashed assets stay available for the cache and rollback windows. A rollback selects a complete previous release. If the host overwrites files in place, the deployment needs another way to keep readers from seeing half of each version.

This is where the freshness budget gets spent: waiting for a build slot, building, uploading, switching, and refreshing caches. A 20-millisecond response from the edge tells me nothing about whether it contains the article I approved ten minutes ago. For a scheduled post, the public route and deployed revision need checking after the release.

When dynamic earns it

A logged-in dashboard needs live authorization and account data. It doesn’t automatically need server-rendered HTML. A static shell can call an authenticated API, with the backend checking permissions on every protected operation. An editor or simulator can do substantial work in the browser too. Shared state and privileged actions are the parts that need a trusted server boundary.

Other pages do earn request-time rendering: output that depends on the request, data that can’t meet its freshness budget through rebuilding, or HTML that needs to arrive already personalized. That decision belongs at the route level. Astro can pre-render public pages and use an appropriate server adapter for on-demand routes; islands can attach interactivity where it’s needed.

PagePrepare ahead of timeKeep live
Public articleComplete HTML and versioned assetsPublication and cache refresh
Account dashboardPublic shell and assetsAuthorized data and mutations
Personalized server routeShared assets and public fragmentsRequest-specific HTML and data access

A static route has less request-time machinery, but the site still has a build system, dependencies, deployment credentials, DNS, CDN configuration, and browser code. A secret embedded during a build is still a leaked secret. Unsafe rich-text rendering can still ship stored script injection. I remove runtime work where it buys nothing; I still review what gets shipped and who can change it.

The test I use is straightforward: can this representation be prepared ahead of requests, shared safely, and updated within its freshness budget? If yes, I start with a file. If a particular route needs live computation, I give it that computation. A document doesn’t earn a server just by being on the web.