BACK TO DIRECTORY
settingintermediate

Next.js Optimized

A battle-tested Next.js configuration for production applications. Includes optimal image configuration with remote patterns, security headers (CSP, HSTS, X-Frame-Options), redirects and rewrites patterns, bundle analyzer integration, and edge runtime configuration. Based on configurations used by high-traffic production Next.js applications.

534 STARS
7.9k DOWNLOADS
claude-templates
nextjsproductionoptimizationsecurityconfig

CONFIGURATION

typescript
1// next.config.ts
2import type { NextConfig } from "next";
3
4const nextConfig: NextConfig = {
5 // Performance
6 reactStrictMode: true,
7 poweredByHeader: false,
8 compress: true,
9
10 // Images
11 images: {
12 formats: ["image/avif", "image/webp"],
13 remotePatterns: [
14 {
15 protocol: "https",
16 hostname: "**.example.com",
17 },
18 ],
19 minimumCacheTTL: 60 * 60 * 24, // 24 hours
20 },
21
22 // Security Headers
23 async headers() {
24 return [
25 {
26 source: "/(.*)",
27 headers: [
28 {
29 key: "X-Frame-Options",
30 value: "DENY",
31 },
32 {
33 key: "X-Content-Type-Options",
34 value: "nosniff",
35 },
36 {
37 key: "Referrer-Policy",
38 value: "strict-origin-when-cross-origin",
39 },
40 {
41 key: "Permissions-Policy",
42 value: "camera=(), microphone=(), geolocation=()",
43 },
44 {
45 key: "Strict-Transport-Security",
46 value: "max-age=31536000; includeSubDomains",
47 },
48 ],
49 },
50 ];
51 },
52
53 // Redirects
54 async redirects() {
55 return [
56 {
57 source: "/old-path",
58 destination: "/new-path",
59 permanent: true,
60 },
61 ];
62 },
63
64 // Experimental features
65 experimental: {
66 typedRoutes: true,
67 },
68};
69
70export default nextConfig;