I am creating SSR project with Nuxt 3.
I am thinking to add Cache-Control
Header to generated static files in .output/_nuxt
directory.
I tried below code server/middleware/cache-control.ts
export default defineEventHandler((event) => {
let res = event.res
const year = 31536000
const tenmin = 600
const url = event.req.url
const maxage = url.match(/(.+)\.(jpg|jpeg|gif|css|png|js|ico|svg|mjs)/) ? year : tenmin
res.setHeader('Cache-Control', `max-age=${maxage} s-maxage=${maxage}`);
})
But, it does not work.
How to add Cache-Control
to the generated static files?
console.log
tells that network does not go through Nuxt3 server. I think I need to configure Vite server. – Lepleynuxt.config.js
. But still does not wok... ``` js export default defineNuxtConfig({ vite: { server: { headers: { "Cache-Control": "max-age=11111, s-maxage=11111" } } } }) ``` – Lepley