-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathnext.config.ts
More file actions
69 lines (62 loc) · 1.66 KB
/
next.config.ts
File metadata and controls
69 lines (62 loc) · 1.66 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
import type { NextConfig } from "next";
import withPWA from "@ducanh2912/next-pwa";
const isDev = process.env.NODE_ENV === "development";
const isTurbopack = !!process.env.TURBOPACK;
const nextConfig: NextConfig = {
reactStrictMode: true,
async headers() {
return [
{
source: "/sw.js",
headers: [
{ key: "Cache-Control", value: "no-cache, no-store, must-revalidate" },
{ key: "Pragma", value: "no-cache" },
{ key: "Expires", value: "0" },
],
},
{
source: "/manifest.json",
headers: [
{ key: "Cache-Control", value: "no-cache, no-store, must-revalidate" },
{ key: "Pragma", value: "no-cache" },
{ key: "Expires", value: "0" },
],
},
];
},
};
const pwa = withPWA({
dest: "public",
disable: isDev,
register: true,
skipWaiting: false,
sw: "sw.js",
runtimeCaching: [
{
// Questions JSON: prefer network for freshness, fallback to cache when offline
urlPattern: /\/questions\/.*\.json$/,
handler: "NetworkFirst",
options: {
cacheName: "questions-json",
expiration: {
maxEntries: 10,
maxAgeSeconds: 7 * 24 * 60 * 60, // 7 days
},
},
},
{
// Question images: prefer cache but revalidate in background to get new images after updates
urlPattern: /\/questions\/images\/.*\.(?:png|jpg|jpeg|gif|webp|svg)$/,
handler: "StaleWhileRevalidate",
options: {
cacheName: "question-images",
expiration: {
maxEntries: 300,
maxAgeSeconds: 30 * 24 * 60 * 60, // 30 days
},
},
},
],
});
const config: NextConfig = isTurbopack ? nextConfig : pwa(nextConfig);
export default config;