From b9c2bc5c70f6f2f7f79fb7d8387e1521d1bda5b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joaqu=C3=ADn=20S=C3=A1nchez?= Date: Sun, 12 Feb 2023 12:08:50 +0100 Subject: [PATCH] fix(pwa): configure sw and web manifest cache control headers (#1724) --- modules/pwa/index.ts | 8 ++++++++ nuxt.config.ts | 1 + 2 files changed, 9 insertions(+) diff --git a/modules/pwa/index.ts b/modules/pwa/index.ts index 520c4b85..14df539a 100644 --- a/modules/pwa/index.ts +++ b/modules/pwa/index.ts @@ -79,6 +79,7 @@ export default defineNuxtModule({ if (entry) { res.statusCode = 200 res.setHeader('Content-Type', 'application/manifest+json') + res.setHeader('Cache-Control', 'public, max-age=0, must-revalidate') res.write(JSON.stringify(entry), 'utf-8') res.end() } @@ -135,15 +136,22 @@ export default defineNuxtModule({ else { nuxt.hook('nitro:config', async (nitroConfig) => { nitroConfig.routeRules = nitroConfig.routeRules || {} + nitroConfig.routeRules!['/sw.js'] = { + headers: { + 'Cache-Control': 'public, max-age=0, must-revalidate', + }, + } for (const locale of pwaLocales) { nitroConfig.routeRules![`/manifest-${locale.code}.webmanifest`] = { headers: { 'Content-Type': 'application/manifest+json', + 'Cache-Control': 'public, max-age=0, must-revalidate', }, } nitroConfig.routeRules![`/manifest-${locale.code}-dark.webmanifest`] = { headers: { 'Content-Type': 'application/manifest+json', + 'Cache-Control': 'public, max-age=0, must-revalidate', }, } } diff --git a/nuxt.config.ts b/nuxt.config.ts index 873a3e89..9008e9e5 100644 --- a/nuxt.config.ts +++ b/nuxt.config.ts @@ -122,6 +122,7 @@ export default defineNuxtConfig({ '/manifest.webmanifest': { headers: { 'Content-Type': 'application/manifest+json', + 'Cache-Control': 'public, max-age=0, must-revalidate', }, }, },