Skip to content

Sample post: placeholder content to show the layout. It will be replaced by real writing.

Ship a static Next.js blog on Cloudflare Pages

Turn a Next.js app into plain HTML with one config line, then deploy it on Cloudflare Pages with preview links for every branch.

By 1 min readNext.js

On this page

A blog does not need a server. With a static export, Next.js writes every page to HTML at build time, and Cloudflare serves those files from its edge.

One line of config

// next.config.mjs
export default {
  output: 'export',
  images: { unoptimized: true },
};

Run npm run build and the site lands in out/. Open any file in it and you will see finished HTML.

Connect the repository

In the Cloudflare dashboard, go to Workers & Pages, create a Pages project and connect your GitHub repository. Use these settings:

  • Build command: npm run build
  • Output directory: out
  • Node version: set NODE_VERSION to 22, or add a .node-version file

Every push to main deploys to production. Every other branch gets its own preview URL, which is handy for checking a post before it goes live.

Add the custom domain

Under Custom domains, add the bare domain and the www name. When the domain's DNS is already on Cloudflare, the records and the HTTPS certificate are created for you.

Why static

  1. Speed: files come straight from the nearest edge location.
  2. Cost: static requests on Pages are free.
  3. Safety: there is no server or database to attack.

Sahadat Husain

Developer, Devsdemy

Builds WordPress plugins and web tools, and writes down what worked.

More to read