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.
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.
/** @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.
{
"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.
Production Case Studies & Capabilities
Explore how these engineering patterns are deployed in production systems and available through client engagements.
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.
Related Technical Articles
Slashing Runaway Cloud Bills: Diagnosing Serverless Loops and Uncached Database Queries
A senior engineer's guide to diagnosing cloud cost spikes, stopping recursive serverless invocation loops, optimizing unindexed database queries, and setting up hard billing circuit-breakers.
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.