Guide · Build

Deploy an animated Next.js site to Vercel or Cloudflare

By Md Mahafuj Alam · Updated

Set output: 'export' in next.config, build, and upload the out folder to any static host. For a scroll story with hundreds of frames, check the host's file-count and file-size limits, put frames in versioned folders, and serve them with a one-year immutable Cache-Control header while HTML stays revalidated. This guide covers the config, what static export cannot do, the verified limits on Cloudflare Pages and Netlify, and the header files for each host.

Turn on static export with output: 'export'

A cinematic scroll story is a front-end experience. Frames, canvas drawing, GSAP and three.js all run in the browser. Nothing needs a server at request time, which makes a static export the simplest and cheapest way to ship it.

Since Next.js 14 the old next export command is gone. You set the output mode in the config instead, and next build writes plain HTML, CSS and JavaScript to an out folder.

next.config.mjsjs
/** @type {import('next').NextConfig} */
const nextConfig = {
  output: 'export',
  trailingSlash: true,
  images: { unoptimized: true },
  basePath: process.env.NEXT_PUBLIC_BASE_PATH || '',
};

export default nextConfig;
  • output: 'export' produces one HTML file per route in out.
  • trailingSlash: true emits /about/index.html instead of /about.html. Every static host serves a folder index without extra rewrite rules.
  • images.unoptimized serves images as they are. The default next/image loader needs a server, so a static export either disables optimisation or uses a custom loader pointing at an image service.
  • basePath stays empty unless you deploy under a subpath; more on that below.

For image sequences, unoptimised images are what you want anyway. Frames should be cut, sized and compressed before the build, usually with ffmpeg.

What a static export cannot do

The Next.js static exports guide lists features that need a Node.js server or request-time logic. These are not supported with output: 'export':

  • Dynamic routes with dynamicParams: true, or without generateStaticParams()
  • Route handlers that read the request; GET handlers marked force-static still work
  • Cookies, Server Actions, Draft Mode and Incremental Static Regeneration
  • rewrites, redirects and headers in next.config
  • Proxy (formerly middleware) and intercepting routes
  • Image optimisation with the default loader

The one that surprises people is headers. Cache rules you write in next.config are ignored in a static export. You set them in the host's own configuration instead, which this guide covers below. Contact forms need a third-party endpoint or a separate function; the site itself cannot process a POST.

Browser APIs such as window are not available while pages prerender at build time. Read them inside useEffect or other client-only code, which is where scroll and canvas logic belongs anyway.

Deploying under a subpath with basePath

If the story lives at example.com/launch rather than its own domain, set basePath: '/launch'. The value is inlined into the client bundle at build time, so a change needs a rebuild. Links made with next/link get the prefix automatically.

Asset paths do not. The Next.js docs state that next/image sources need the base path added by hand, and the same applies to every frame URL your loader builds. Read it from one environment variable so the config and the loader can never disagree.

lib/frames.tsts
const base = process.env.NEXT_PUBLIC_BASE_PATH || '';

export function frameUrl(index: number): string {
  const n = String(index + 1).padStart(4, '0');
  return `${base}/frames/hero-v3/${n}.webp`;
}

Build with NEXT_PUBLIC_BASE_PATH=/launch npx next build and test the out folder under that path before you upload. A missing prefix shows up as a blank canvas and a column of 404s in the network panel.

File counts and file sizes per host

A scroll story with separate desktop and portrait frame sets, plus a light preview tier, can easily reach a few thousand files. That is well within the limits below, but large catalogues or several stories on one site can approach them. These figures come from each vendor's own documentation.

HostFilesLargest single fileSource
Cloudflare Pages20,000 per site on Free; 100,000 on paid plans, enabled with PAGES_WRANGLER_MAJOR_VERSION=425 MiB per assetPages limits
NetlifyNo limit per deploy; 54,000 files per directoryNo limit stated on the deploy overviewDeploy overview
VercelNo upper limit on build output files; builds over 45 minutes failCheck the limits page; CLI source uploads have their own capsVercel limits

The Netlify per-directory cap is worth designing around even if you never use Netlify: one folder per frame set keeps directories small and makes cache rules simple. Frames themselves are tiny relative to the 25 MiB Cloudflare ceiling; the file that usually breaks it is an uncompressed source video left in public. Keep source footage out of the build.

Cache headers for frames: immutable, versioned folders

Frames never change once published. If you change footage, you publish new frames. That makes them ideal for the longest cache web.dev recommends for versioned URLs: max-age=31536000, one year, with the optional immutable directive so supporting browsers skip revalidation.

The catch is the word versioned. Next.js fingerprints its own JavaScript and CSS under /_next/static/, but files in public keep their names. If you re-export frames into the same folder, returning visitors keep the old ones for a year. Put the version in the folder name, such as /frames/hero-v3/ or a short content hash, and change it whenever the frames change. HTML stays revalidated so it always points at the current folder.

Cloudflare Pages and Netlify

Both read a plain-text _headers file from the published folder. Put it in public and Next.js copies it into out.

public/_headerstext
/frames/*
  Cache-Control: public, max-age=31536000, immutable

/_next/static/*
  Cache-Control: public, max-age=31536000, immutable

Cloudflare Pages allows up to 100 header rules in this file. Netlify also accepts the same rules as [[headers]] tables in netlify.toml.

Vercel

Vercel reads headers from vercel.json at the project root.

vercel.jsonjson
{
  "headers": [
    {
      "source": "/frames/(.*)",
      "headers": [
        { "key": "Cache-Control", "value": "public, max-age=31536000, immutable" }
      ]
    }
  ]
}

After deploying, open the network panel, reload twice and check that frame requests are served from cache. The canvas image sequence guide explains how the loader requests frames so caching and preloading work together.

Deploying to Cloudflare Pages and Vercel

Cloudflare Pages

  1. In the Cloudflare dashboard, go to Workers & Pages, then Create application, Pages, Connect to Git, and pick the repository.
  2. Set the build command to npx next build and the output directory to out.
  3. Add NEXT_PUBLIC_BASE_PATH as an environment variable only if you deploy under a subpath.
  4. Deploy. Each push gets a preview URL on pages.dev.

Cloudflare Pages builds time out after 20 minutes. Frames are copied, not processed, so this rarely matters; generate frames before you commit rather than in the build.

Vercel

Import the repository. Vercel detects Next.js and runs next build; with output: 'export' set, it serves the static output. Add the vercel.json above for frame caching.

Custom domains and the CDN

All three hosts serve static files from a global CDN, so frames are delivered from an edge near the visitor once cached. You do not need a separate CDN in front.

On Cloudflare Pages, a subdomain such as launch.example.com only needs a CNAME at your DNS provider pointing to your-project.pages.dev. An apex domain such as example.com must be a Cloudflare zone, with your nameservers moved to Cloudflare. Start in the dashboard's custom domain flow before you add DNS records; Cloudflare warns that adding the CNAME on its own leads to a 522 error. Vercel and Netlify each have their own domain screens that show the exact records to add.

Once the domain resolves, run a final check: frames load from the custom domain, cache headers are present, and the reduced-motion path still works. The Core Web Vitals guide covers what to measure next. For a starting point, browse the template catalogue; the Kestra template, for example, delivers 443 frames, about 26 MB, in two tiers. For the full build from idea to launch, read the complete guide to building a 3D website with Claude.

FAQ

Questions, answered.

The questions people ask most about this topic.

01Does a Next.js static export need a Node.js server?

No. With output: 'export', next build writes plain HTML, CSS and JavaScript to the out folder, which any static host or web server can serve.

02Why are my cache headers in next.config ignored?

The headers, rewrites and redirects options in next.config are not supported in a static export. Set headers in the host instead: a _headers file on Cloudflare Pages or Netlify, or vercel.json on Vercel.

03How many files can I deploy to Cloudflare Pages?

Cloudflare's documentation lists 20,000 files per site on the Free plan and 100,000 on paid plans, with a maximum of 25 MiB per file. Check the Pages limits page before launch, because vendors revise these figures.

04Should animation frames use the immutable cache directive?

Yes, as long as each frame set lives in a versioned folder whose name changes when the frames change. Then a one-year max-age with immutable is safe, and HTML points visitors at the new folder.

05Do I need basePath for a custom domain?

No. basePath is only for serving the site under a subpath such as example.com/launch. A site on its own domain or subdomain leaves it empty.