Skip to content

No. 61Next.js7 min read1,968 words

Ship a fast marketing site: without a database in Next.js

How to build a fast, SEO-first marketing site in Next.js without a database: static rendering, typed MDX content, forms without tables, and when you need a DB.

Written by
Lazy Devs
Published
Updated
Sources
Cited inline

Key takeaways · 05

The short version

  1. 01Most marketing, agency and brochure sites do not need a runtime database. Prerender every page to static HTML at build time and serve it from a CDN.
  2. 02In the Next.js App Router, a route is prerendered automatically when it reads no request data. Add generateStaticParams for dynamic segments so every post or page exists at build time.
  3. 03Keep content in typed MDX or a headless CMS read at build time. Validating frontmatter with a schema turns a broken date or missing title into a failed build, not a broken page.
  4. 04Forms, search and newsletters do not need your own database: a single Route Handler can email form submissions, and a build-time JSON index handles search for a few hundred pages.
  5. 05Add a database the day the product becomes stateful, with user accounts, frequent writes or per-user data, not before.
On this page · 11

Most marketing sites do not need a database. If your content changes a few times a week rather than on every request, the fastest, cheapest and most reliable setup is to prerender every page to static HTML at build time, serve it from a CDN, and handle the few interactive bits, like a contact form, with a single serverless function. You get instant page loads, nothing to patch at 3am, and a hosting bill close to zero.

Yet a surprising number of marketing sites ship with a Postgres instance, an ORM, a connection pool and a monthly bill, all to serve words and images. That is the wrong default. It adds cost, latency and a moving part that can fail, in exchange for flexibility the site never uses.

The approach we reach for first is the opposite, and this site is built that way: every page is prerendered, the blog is local MDX, and the only code that runs per request is the contact form endpoint. Here is how it works, and where the line actually is.

Why static wins for content sites

When every page is prerendered, there is no server work on the request path. The CDN returns bytes that already exist.

Static site (prerendered)Database-backed site
Request pathCDN returns a fileFunction starts, queries database, renders HTML
Time to first byteCDN lookupServer render plus database round trips
Behaviour under a traffic spikeMore CDN readsConnection limits, slow queries, timeouts
Running costClose to free for most sitesDatabase plus compute, billed whether busy or idle
Attack surfaceAlmost none at runtimeDatabase credentials, injection risks, patching
Content updatesRebuild or revalidateInstant writes

The speed advantage shows up directly in the metrics Google uses. A prerendered page served from a CDN starts every part of Largest Contentful Paint from a better place, because the HTML arrives immediately and includes the content. That is why static rendering is the foundation of our performance and SEO engineering work: the fastest request is the one your server never has to think about.

What "static" means in Next.js 16

The App Router prerenders a route automatically when nothing in it reads request-time data like cookies, headers or search params. For a content site that is most routes by default. You have two ways to ship the result:

OptionWhat you getWhat you give up
Prerendered on a Next.js-aware hostStatic HTML on a CDN, plus Route Handlers, image optimization, redirects and on-demand revalidationNeeds a platform that runs Next.js
Static export (output: "export")Plain HTML, CSS and JS you can host on any static file serverRoute Handlers that read the request (so no built-in form endpoint), Server Actions, cookies, Proxy, redirects and headers config, ISR, draft mode, and the default image loader

The static exports guide lists exactly what is unsupported. For most marketing sites we prefer the first option: pages are still static, but you keep a contact form endpoint, built-in image optimization and the ability to update a single page without a full rebuild. Choose static export when you genuinely want zero server code, or a host that only serves files.

For dynamic segments like blog posts, use generateStaticParams so every page exists at build time:

// app/blog/[slug]/page.tsx
import { notFound } from "next/navigation";
import { posts } from "#site/content";
 
export function generateStaticParams() {
  return posts.map((post) => ({ slug: post.slug }));
}
 
export const dynamicParams = false; // unknown slugs return 404
 
export default async function PostPage({
  params,
}: {
  params: Promise<{ slug: string }>;
}) {
  const { slug } = await params;
  const post = posts.find((p) => p.slug === slug);
  if (!post) notFound();
  return <Article post={post} />;
}

After next build, check the route summary: every content route should be marked static. If one is not, something reads request data, and our mental model for App Router rendering explains how to track it down.

Where the content lives

Without a database, content needs a home. There are three good options, and they are not mutually exclusive.

Typed MDX files in the repository

This is what we use for blogs and documentation, including this website. Each post is a Markdown or MDX file with frontmatter, compiled at build time by a content layer such as Velite, which validates every file against a schema. A simplified version of the kind of schema we use:

// velite.config.ts
import { defineCollection, s } from "velite";
 
const posts = defineCollection({
  name: "Post",
  pattern: "blog/**/*.mdx",
  schema: s.object({
    title: s.string().max(99),
    excerpt: s.string().max(160),
    date: s.isodate(),
    tags: s.array(s.string()).default([]),
    content: s.markdown(),
  }),
});

A typo in a date, a missing title or a meta description that runs too long fails the build instead of shipping broken metadata to production. Your content gets the same type safety as the rest of the codebase, content changes go through pull requests with previews, and you have full version history for free.

A headless CMS read at build time

For teams where marketers publish without developers, a headless CMS is the better editing experience. Our roundup of the best headless CMS options compares the main choices. The site fetches content at build time (or caches it and revalidates on publish), so it stays static; only the source of the words changes. Our guide to choosing a headless CMS for marketing teams covers the options.

Plain data files

Team members, pricing tiers, FAQs and service descriptions often fit perfectly in a TypeScript or JSON file. They are typed, reviewed in pull requests and imported directly by the pages that use them.

The dynamic parts, without a database

This is where people assume they need a database. Usually they do not.

FeatureDatabase-free approachNotes
Contact formRoute Handler that validates and sends email via a transactional providerThe inbox is the database
Newsletter signupPost directly to your email platform's APIThe platform stores subscribers
Site searchJSON index built at build time, filtered on the clientFine for hundreds of pages; use a hosted search service beyond that
AnalyticsA privacy-respecting analytics service or GA4 with consentNo tables of your own
Comments and reviewsEmbedded third-party serviceOnly if you really need them
Gated downloadsEmail the file link after form submissionNo accounts needed

A contact form in one Route Handler

// app/api/contact/route.ts
import { z } from "zod";
 
const Schema = z.object({
  name: z.string().min(1).max(100),
  email: z.string().email(),
  message: z.string().min(10).max(5000),
  company_hp: z.string().optional(), // honeypot: hidden, real users leave it empty
});
 
export async function POST(req: Request) {
  const parsed = Schema.safeParse(await req.json());
 
  // Bots fill the hidden field. Pretend it worked, but send nothing.
  if (parsed.success && parsed.data.company_hp) {
    return Response.json({ ok: true });
  }
  if (!parsed.success) {
    return Response.json({ error: "Invalid input" }, { status: 400 });
  }
 
  await sendEmail({
    to: process.env.CONTACT_TO!,
    subject: `New enquiry from ${parsed.data.name}`,
    replyTo: parsed.data.email,
    text: parsed.data.message,
  });
 
  return Response.json({ ok: true });
}

Validate on the server, add a hidden honeypot field, and put a simple rate limit in front of the endpoint. When the honeypot is filled, return success without sending anything, so bots get no signal to adapt. Name the honeypot something autofill will not recognise; a field called website or email2 can get filled in by real users' browsers and silently reject genuine enquiries.

The rule of thumb: if the data is read far more often than it is written, and it changes on a human schedule rather than per request, you do not need a runtime database to serve it.

Updating content without a full rebuild

Rebuilding the whole site on every typo fix is fine for small sites, and builds of a few hundred static pages are usually quick. As the site grows, or when the content lives in a CMS, revalidate only what changed. A CMS webhook can call a Route Handler that invalidates a tag or path, and the next visitor gets the fresh page while everything else stays cached. The Incremental Static Regeneration guide covers time-based and on-demand options, and our explainer on Next.js caching covers revalidateTag and updateTag in Next.js 16.

The SEO payoff

Static rendering and SEO reinforce each other. Because the HTML is final at build time:

  • The title, meta description, canonical URL and Open Graph tags are in the very first response.
  • Structured data is generated from the same typed content, so it never drifts from the page.
  • The sitemap is generated from the content collection with real publish and update dates.
  • Crawlers never wait on client-side JavaScript to see the content.

Pair that with disciplined images, fonts and client JavaScript, and passing Core Web Vitals becomes the default rather than a project. Our Core Web Vitals checklist is the standard we ship every site against, and our web performance statistics show how few sites manage it.

Is a static site right for you?

A static, database-free build is the right default if most of these are true:

  • Content changes daily or less often, not per visitor.
  • Visitors read; they do not log in, buy or book on the site itself.
  • The interactive pieces are forms, signups and search.
  • Speed, search rankings and low running costs matter more than real-time content.
  • Your team is happy publishing through Git or a headless CMS.

If you ticked most of them, you are building a content site, and a database would be paying rent for an empty room. If you are building a product with accounts and state, start from a different guide, such as choosing a tech stack for an application.

A build plan that works

  1. List the content types: pages, posts, services, team, FAQs. Decide whether each lives in MDX, a data file or a CMS.
  2. Define schemas for each content type, so invalid content fails the build.
  3. Build pages as Server Components that read content at build time, with generateStaticParams for dynamic routes.
  4. Generate metadata, sitemap and structured data from the same content.
  5. Add the one or two endpoints you need, typically the contact form, with validation and spam protection.
  6. Check the build output to confirm every content route is static.
  7. Measure in the field after launch and keep an eye on JavaScript creep.

Common mistakes

  • Accidentally going dynamic. Reading cookies in a root layout, for a theme or consent banner, can make every page render per request. Read client-only preferences in a small Client Component instead.
  • Shipping a heavy client bundle anyway. Static HTML does not help if every section is a client component with animation libraries attached.
  • Forgetting images in static export. The default next/image loader needs a server; use a custom loader or a host that supports optimization.
  • Forms without spam protection, which quickly fill your inbox.
  • Adding a database for one feature that a hosted service would cover.

When you actually do need a database

To be fair to databases: the moment content is per user, written frequently, or queried in ways a flat file cannot answer, a database earns its place. Accounts and logins, orders and payments, bookings and availability, user-generated content, and dashboards all need real persistence. The mistake is not using a database. It is reaching for one before the product needs it, then paying for it on a site that only serves words and images.

Default to static. Keep content in typed files or a CMS read at build time, push the few interactive pieces to a single function or a hosted service, and add a database the day the product genuinely becomes stateful.

If you want a marketing site that loads instantly, ranks well and costs almost nothing to run, that is exactly what our Next.js development team builds. Tell us about your site.

FAQ · 05 questions

Frequently asked questions

Does a Next.js website need a database?

No. A Next.js site can read its content from files or a headless CMS at build time and serve every page as static HTML. You only need a database when the site stores data at runtime, such as user accounts, orders, bookings or anything written frequently by visitors.

What is the difference between static export and static rendering in Next.js?

Static rendering means Next.js prerenders pages to HTML at build time but still runs on a platform that supports server features like Route Handlers, image optimization and revalidation. Static export, enabled with output set to export, produces plain files you can host anywhere, but drops server features such as Route Handlers that read the request, Server Actions, cookies, the default image loader and Incremental Static Regeneration.

How do I handle a contact form on a static Next.js site?

Post the form to a single Route Handler that validates the input and sends it through a transactional email provider. Add a honeypot field and basic rate limiting to stop spam. The submission lands in your inbox, so there is no table to secure, back up or build an admin screen for.

Can marketing teams update a static site without a developer?

Yes, with a headless CMS. Editors publish in the CMS, and a webhook tells the site to rebuild or to revalidate only the affected pages. The site stays static and fast, while content changes go live within moments of publishing.

Is a static site better for SEO?

It usually helps. Every page arrives as complete HTML with its title, description, canonical URL and structured data already in place, and it is served quickly from a CDN, which supports good Core Web Vitals. Content quality still matters most, but a static site removes the technical reasons a good page might underperform.

Related service

Next.js Development Services

Production Next.js apps and sites, tuned for speed and search.

Learn more

Next step

Want this built right?

This is the work we do every day. Tell us what you are building and we will show you exactly how we would ship it.

First reply
Within 1 business day
Typical start
1–2 weeks
Pricing
Fixed price per phase
You own
All code and accounts