fix(frontend): move cache control to route rules

This commit is contained in:
MiniDigger | Martin 2022-12-22 16:33:45 +01:00
parent 347e72de0c
commit 004d6e2e85
2 changed files with 10 additions and 8 deletions

View File

@ -88,6 +88,16 @@ export default defineNuxtConfig({
"/oauth/logout": defineProxyAuth(),
},
},
// cache statics for a year
routeRules: {
"/_nuxt/**": { headers: { "Cache-Control": "max-age=31536000, immutable" } },
"/**/*.js": { headers: { "Cache-Control": "max-age=31536000, immutable" } },
"/**/*.mjs": { headers: { "Cache-Control": "max-age=31536000, immutable" } },
"/**/*.css": { headers: { "Cache-Control": "max-age=31536000, immutable" } },
"/**/*.json": { headers: { "Cache-Control": "max-age=31536000, immutable" } },
"/**/*.xml": { headers: { "Cache-Control": "max-age=31536000, immutable" } },
"/**/*.svg": { headers: { "Cache-Control": "max-age=31536000, immutable" } },
},
});
function defineProxyAuth(): ProxyOptions {

View File

@ -1,8 +0,0 @@
export default defineEventHandler((event) => {
const statics = 31536000; // 1 year
const other = 60 * 60; // 1 hour
const url = event.node.req.url;
if (url?.startsWith("/api")) return;
const maxage = url?.match(/(.+)\.(jpg|jpeg|webp|gif|css|png|js|ico|svg|mjs)/) ? statics : other;
event.node.res.setHeader("Cache-Control", `max-age=${maxage} s-maxage=${maxage}`);
});