fix(pwa): configure sw and web manifest cache control headers (#1724)

pull/1727/head
Joaquín Sánchez 2023-02-12 12:08:50 +01:00 zatwierdzone przez GitHub
rodzic c2ffdcf78b
commit b9c2bc5c70
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
2 zmienionych plików z 9 dodań i 0 usunięć

Wyświetl plik

@ -79,6 +79,7 @@ export default defineNuxtModule<VitePWANuxtOptions>({
if (entry) { if (entry) {
res.statusCode = 200 res.statusCode = 200
res.setHeader('Content-Type', 'application/manifest+json') 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.write(JSON.stringify(entry), 'utf-8')
res.end() res.end()
} }
@ -135,15 +136,22 @@ export default defineNuxtModule<VitePWANuxtOptions>({
else { else {
nuxt.hook('nitro:config', async (nitroConfig) => { nuxt.hook('nitro:config', async (nitroConfig) => {
nitroConfig.routeRules = nitroConfig.routeRules || {} nitroConfig.routeRules = nitroConfig.routeRules || {}
nitroConfig.routeRules!['/sw.js'] = {
headers: {
'Cache-Control': 'public, max-age=0, must-revalidate',
},
}
for (const locale of pwaLocales) { for (const locale of pwaLocales) {
nitroConfig.routeRules![`/manifest-${locale.code}.webmanifest`] = { nitroConfig.routeRules![`/manifest-${locale.code}.webmanifest`] = {
headers: { headers: {
'Content-Type': 'application/manifest+json', 'Content-Type': 'application/manifest+json',
'Cache-Control': 'public, max-age=0, must-revalidate',
}, },
} }
nitroConfig.routeRules![`/manifest-${locale.code}-dark.webmanifest`] = { nitroConfig.routeRules![`/manifest-${locale.code}-dark.webmanifest`] = {
headers: { headers: {
'Content-Type': 'application/manifest+json', 'Content-Type': 'application/manifest+json',
'Cache-Control': 'public, max-age=0, must-revalidate',
}, },
} }
} }

Wyświetl plik

@ -122,6 +122,7 @@ export default defineNuxtConfig({
'/manifest.webmanifest': { '/manifest.webmanifest': {
headers: { headers: {
'Content-Type': 'application/manifest+json', 'Content-Type': 'application/manifest+json',
'Cache-Control': 'public, max-age=0, must-revalidate',
}, },
}, },
}, },