next.js配置图片资源缓存

40 阅读1分钟

HTTP 缓存的时间设置max-age=31536000 就是 1 年

所有 /images/ 下的静态资源(包括 GIF)会被浏览器缓存 1 年


const const nextConfig = {
  async headers() {
    return [
      {
        source: '/images/:path*',
        headers: [
          {
            key: 'Cache-Control',
            value: 'public, max-age=31536000, immutable',
          },
        ],
      },
    ];
  }
 }