Skip to content

Commit

Permalink
fix(pwa): configure sw and web manifest cache control headers (#1724)
Browse files Browse the repository at this point in the history
  • Loading branch information
userquin committed Feb 12, 2023
1 parent c2ffdcf commit b9c2bc5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
8 changes: 8 additions & 0 deletions modules/pwa/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export default defineNuxtModule<VitePWANuxtOptions>({
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()
}
Expand Down Expand Up @@ -135,15 +136,22 @@ export default defineNuxtModule<VitePWANuxtOptions>({
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',
},
}
}
Expand Down
1 change: 1 addition & 0 deletions nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ export default defineNuxtConfig({
'/manifest.webmanifest': {
headers: {
'Content-Type': 'application/manifest+json',
'Cache-Control': 'public, max-age=0, must-revalidate',
},
},
},
Expand Down

0 comments on commit b9c2bc5

Please sign in to comment.