fix(pwa): add ignore vary to web manifests and emoji handlers

This commit is contained in:
userquin 2023-11-02 12:31:49 +01:00
parent 5d09e7d2ab
commit 059502f3e2

View file

@ -44,9 +44,9 @@ if (import.meta.env.PROD) {
// exclude shiki: has its own cache // exclude shiki: has its own cache
/^\/emojis\//, /^\/emojis\//,
// exclude sw: if the user navigates to it, fallback to index.html // exclude sw: if the user navigates to it, fallback to index.html
/^\/sw.js$/, /^\/sw\.js$/,
// exclude webmanifest: has its own cache // exclude webmanifest: has its own cache, if the user navigates to it, fallback to index.html
/^\/manifest-(.*).webmanifest$/, /^\/manifest-(.*)\.webmanifest$/,
] ]
} }
@ -54,10 +54,14 @@ if (import.meta.env.PROD) {
if (import.meta.env.PROD) { if (import.meta.env.PROD) {
// include webmanifest cache // include webmanifest cache
registerRoute( registerRoute(
({ request, sameOrigin }) => ({ request, sameOrigin, url }) =>
sameOrigin && request.destination === 'manifest', sameOrigin && request.destination === 'manifest' && url.pathname.startsWith('/manifest-'),
new NetworkFirst({ new NetworkFirst({
cacheName: 'elk-webmanifest', cacheName: 'elk-webmanifest',
// responses with a Vary: Accept-Encoding header
matchOptions: {
ignoreVary: true,
},
plugins: [ plugins: [
new CacheableResponsePlugin({ statuses: [200] }), new CacheableResponsePlugin({ statuses: [200] }),
// we only need a few entries // we only need a few entries
@ -86,6 +90,10 @@ if (import.meta.env.PROD) {
&& url.pathname.startsWith('/emojis/'), && url.pathname.startsWith('/emojis/'),
new StaleWhileRevalidate({ new StaleWhileRevalidate({
cacheName: 'elk-emojis', cacheName: 'elk-emojis',
// responses with a Vary: Accept-Encoding header
matchOptions: {
ignoreVary: true,
},
plugins: [ plugins: [
new CacheableResponsePlugin({ statuses: [200] }), new CacheableResponsePlugin({ statuses: [200] }),
// 15 days max // 15 days max