Adam BlansettSenior Full-Stack & AI Engineer
Full-Stack Web
6 min read
Adam Blansett

Deterministic Static Next.js with App Router and Firebase Hosting

Deploy lightweight, static Next.js 16 applications to Firebase Hosting with cacheable CDN delivery, declarative security headers, and no server to manage.

Next.jsTypeScriptFirebaseDevOpsPerformanceWeb

While Next.js is frequently associated with dynamic Node.js server runtimes, server-side rendering (SSR), and streaming servers, many high-value production websites and client portals thrive on static exports. Pre-rendering every route at build time yields predictable costs, CDN-cacheable delivery, and removes the operational overhead of managing containerized Node processes.

By configuring Next.js App Router for static export (`output: 'export'`) combined with Firebase Hosting's global CDN and security rules, you get a lightweight, predictable delivery path with no server runtime to operate.

Configuring the Static Export Pipeline#

In `next.config.mjs`, setting `output: 'export'` instructs the Next.js compiler to generate HTML, CSS, JavaScript, and asset bundles directly into the `out/` directory. Enabling `trailingSlash: true` ensures that every generated route produces a directory containing an `index.html` file, matching Firebase Hosting's clean URL routing conventions.

Pipeline diagram: Next.js App Router with output export runs next build and produces the out directory containing HTML, _next/static and assets, which Firebase Hosting serves with clean URLs, trailing slashes, security headers and immutable caching. A GitHub Actions workflow runs npm run verify before deploying. There is no server runtime.
Static export pipeline: App Router, `output: 'export'`, `next build`, the `out/` directory, then Firebase Hosting. No Node server runtime or Cloud Functions are involved on this site.
next.config.mjs
/** @type {import('next').NextConfig} */
const nextConfig = {
  output: 'export',
  trailingSlash: true,
  images: {
    unoptimized: true, // Static CDN hosting
  },
};

export default nextConfig;

Production Security Headers on Firebase Hosting#

Because static sites do not run server-side Express or Node middleware to attach HTTP response headers, these must be configured declaratively within `firebase.json`. This provides defence-in-depth against clickjacking, MIME-type sniffing, and cross-site scripting.

firebase.json
{
  "hosting": {
    "public": "out",
    "cleanUrls": true,
    "trailingSlash": true,
    "headers": [
      {
        "source": "**",
        "headers": [
          { "key": "X-Content-Type-Options", "value": "nosniff" },
          { "key": "X-Frame-Options", "value": "DENY" },
          { "key": "Referrer-Policy", "value": "strict-origin-when-cross-origin" },
          { "key": "Permissions-Policy", "value": "camera=(), microphone=(), geolocation=()" },
          { "key": "Strict-Transport-Security", "value": "max-age=31536000; includeSubDomains; preload" }
        ]
      },
      {
        "source": "/_next/static/**",
        "headers": [
          { "key": "Cache-Control", "value": "public, max-age=31536000, immutable" }
        ]
      }
    ]
  }
}

Handling Dynamic Needs via Cloud Functions#

When a static website needs to process dynamic operations—such as payment webhooks, contact form dispatch, or scheduling notifications—you can route specific endpoints to isolated Firebase Cloud Functions without forfeiting the benefits of static asset delivery.

This deployment pattern can be useful for websites that benefit from pre-rendered pages and cacheable static assets. The right hosting model depends on each application's dynamic requirements and operational constraints. To explore a web platform or hosting approach, see my Full-Stack Engineering Services.

Applied Architecture

Production Case Studies & Capabilities

Explore how these engineering patterns are deployed in production systems and available through client engagements.

Related Engineering Service

Full-Stack Engineering

Companies often struggle with fragile web applications, slow delivery cycles, and disjointed client-server boundaries. I build robust, production-grade applications that scale seamlessly from day one without architectural debt.

Share this technical guide

Need Help Solving This in Your Application?

I partner with founders, executives, and engineering leaders to design architectures, resolve production bottlenecks, and deliver resilient software.

Related Technical Articles

Software Architecture
13 min read

How to Find Out Why Your App Works Locally but Fails in Production

A systematic engineering guide to diagnosing environment drift, missing build configurations, CORS, connection strings, and production runtime failures.

Production ReadinessDevOpsNext.jsEnvironment ConfigurationDebuggingFull-Stack
Read Article