-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathnext.config.unified.ts
More file actions
237 lines (221 loc) · 6.22 KB
/
next.config.unified.ts
File metadata and controls
237 lines (221 loc) · 6.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
/**
* UNIFIED NEXT.JS CACHE CONFIGURATION
*
* This replaces the existing complex header configuration with
* a simplified, consistent approach that aligns with our
* unified cache system.
*/
import type { NextConfig } from 'next';
const isDev = process.env.NODE_ENV === 'development';
const isProd = process.env.NODE_ENV === 'production';
const buildId = process.env.BUILD_ID || process.env.VERCEL_GIT_COMMIT_SHA?.substring(0, 7) || Date.now().toString();
const nextConfig: NextConfig = {
// ... existing config ...
experimental: {
optimizeCss: true,
optimizePackageImports: ['@headlessui/react', '@heroicons/react'],
},
eslint: {
ignoreDuringBuilds: true,
},
typescript: {
ignoreBuildErrors: true,
},
/**
* UNIFIED CACHE HEADERS
*
* Simplified to match our unified cache strategies:
* - Static assets: 1 year cache with immutable
* - Dynamic content: 1-2 min CDN + SWR for fast updates
* - API responses: 30-60s CDN + SWR
* - User-specific: no cache
*/
async headers() {
return [
// === STATIC ASSETS ===
{
source: '/_next/static/(.*)',
headers: [
{
key: 'Cache-Control',
value: isDev
? 'no-cache, no-store, must-revalidate'
: 'public, max-age=31536000, immutable', // 1 year
},
{
key: 'CDN-Cache-Control',
value: isProd ? 'public, max-age=31536000, immutable' : 'no-cache',
},
{
key: 'Cache-Tag',
value: 'static',
},
],
},
// === STATIC ASSETS (PUBLIC FOLDER) ===
{
source: '/(images|media|assets)/:path*.(jpg|jpeg|png|gif|webp|svg|ico|woff|woff2|ttf|eot)',
headers: [
{
key: 'Cache-Control',
value: isDev
? 'no-cache, no-store, must-revalidate'
: 'public, max-age=2592000, immutable', // 30 days (safe for manually managed assets)
},
{
key: 'CDN-Cache-Control',
value: isProd ? 'public, max-age=2592000' : 'no-cache',
},
{
key: 'Cache-Tag',
value: 'static',
},
],
},
// === DYNAMIC CONTENT PAGES ===
{
source: '/(hackathons|events|blog|leaderboard|tests)/:path*',
headers: [
{
key: 'Cache-Control',
value: isDev
? 'no-cache, no-store, must-revalidate'
: 'public, max-age=0, s-maxage=60, stale-while-revalidate=300', // 1min CDN, 5min SWR
},
{
key: 'CDN-Cache-Control',
value: isProd ? 'public, max-age=60, stale-while-revalidate=300' : 'no-cache',
},
{
key: 'Cache-Tag',
value: 'pages,content',
},
{
key: 'X-Build-ID',
value: buildId,
},
],
},
// === API ROUTES (STANDARD) ===
{
source: '/api/(hackathons|events|leaderboard|tests)/:path*',
headers: [
{
key: 'Cache-Control',
value: isDev
? 'no-cache, no-store, must-revalidate'
: 'public, max-age=0, s-maxage=30, stale-while-revalidate=120', // 30s CDN, 2min SWR
},
{
key: 'CDN-Cache-Control',
value: isProd ? 'public, max-age=30, stale-while-revalidate=120' : 'no-cache',
},
{
key: 'Cache-Tag',
value: 'api',
},
{
key: 'X-Build-ID',
value: buildId,
},
],
},
// === REAL-TIME API ROUTES ===
{
source: '/api/(ai|chat)/:path*',
headers: [
{
key: 'Cache-Control',
value: isDev
? 'no-cache, no-store, must-revalidate'
: 'public, max-age=0, s-maxage=5, stale-while-revalidate=60', // 5s CDN, 1min SWR
},
{
key: 'CDN-Cache-Control',
value: isProd ? 'public, max-age=5, stale-while-revalidate=60' : 'no-cache',
},
{
key: 'Cache-Tag',
value: 'realtime',
},
],
},
// === USER-SPECIFIC/AUTHENTICATED ROUTES ===
{
source: '/(protected|admin|profile|dashboard)/:path*',
headers: [
{
key: 'Cache-Control',
value: 'private, no-cache, no-store, must-revalidate',
},
{
key: 'CDN-Cache-Control',
value: 'no-cache',
},
{
key: 'Cache-Tag',
value: 'private',
},
],
},
// === USER-SPECIFIC API ROUTES ===
{
source: '/api/(auth|user|admin|premium|internships)/:path*',
headers: [
{
key: 'Cache-Control',
value: 'private, no-cache, no-store, must-revalidate',
},
{
key: 'CDN-Cache-Control',
value: 'no-cache',
},
{
key: 'Cache-Tag',
value: 'private',
},
],
},
// === WEBHOOKS (NO CACHE) ===
{
source: '/api/webhooks/:path*',
headers: [
{
key: 'Cache-Control',
value: 'no-cache, no-store, must-revalidate',
},
{
key: 'CDN-Cache-Control',
value: 'no-cache',
},
],
},
// === DEFAULT PUBLIC PAGES ===
{
source: '/((?!api|_next|protected|admin|profile|dashboard).*)',
headers: [
{
key: 'Cache-Control',
value: isDev
? 'no-cache, no-store, must-revalidate'
: 'public, max-age=0, s-maxage=120, stale-while-revalidate=600', // 2min CDN, 10min SWR
},
{
key: 'CDN-Cache-Control',
value: isProd ? 'public, max-age=120, stale-while-revalidate=600' : 'no-cache',
},
{
key: 'Cache-Tag',
value: 'pages',
},
{
key: 'X-Build-ID',
value: buildId,
},
],
},
];
},
// ... rest of existing config ...
};
export default nextConfig;