I'm using Nuxt 3 to create an SSR project. I'm thinking of adding theCache-Control
header to the generated static files in the.output/_nuxt
directory.
I tried the following codeserver/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 doesn't work.
How to addCache-Control
to the generated static files?
For Nuxt3, I use it as server middleware
server/middleware/cache-control.js
I'll figure it out myself. Adding the following code to nuxt.config.js will append cache controls to static files. thank you for your support!