From 55e855181d0a26e409235995cb60c7bedb22ef08 Mon Sep 17 00:00:00 2001 From: userquin Date: Thu, 2 Nov 2023 15:16:37 +0100 Subject: [PATCH] chore: revert changes to use network first --- config/pwa.ts | 4 ++-- service-worker/sw.ts | 18 +++++------------- 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/config/pwa.ts b/config/pwa.ts index abbc523c..19c82b7f 100644 --- a/config/pwa.ts +++ b/config/pwa.ts @@ -13,8 +13,8 @@ export const pwa: VitePWANuxtOptions = { includeManifestIcons: false, manifest: false, injectManifest: { - globPatterns: ['**/*.{js,json,css,html,txt,svg,png,ico,webp,woff,woff2,ttf,eot,otf,wasm,webmanifest}'], - globIgnores: ['emojis/**', 'shiki/**'/* , 'manifest**.webmanifest', 'pwa-*.png', 'maskable-icon.png', 'shortcuts/**', 'screenshots/**' */], + globPatterns: ['**/*.{js,json,css,html,txt,svg,png,ico,webp,woff,woff2,ttf,eot,otf,wasm}'], + globIgnores: ['emojis/**', 'shiki/**', 'manifest**.webmanifest'], manifestTransforms: [(entries) => { const manifest = entries.map((entry) => { if (entry.url.length > 1 && entry.url[0] !== '/') diff --git a/service-worker/sw.ts b/service-worker/sw.ts index df909d6b..61d7b5c5 100644 --- a/service-worker/sw.ts +++ b/service-worker/sw.ts @@ -3,7 +3,7 @@ import { cleanupOutdatedCaches, createHandlerBoundToURL, precacheAndRoute } from 'workbox-precaching' import { NavigationRoute, registerRoute } from 'workbox-routing' import { CacheableResponsePlugin } from 'workbox-cacheable-response' -import { StaleWhileRevalidate } from 'workbox-strategies' +import { NetworkFirst, StaleWhileRevalidate } from 'workbox-strategies' import { ExpirationPlugin } from 'workbox-expiration' import { onNotificationClick, onPush } from './web-push-notifications' @@ -33,7 +33,6 @@ if (import.meta.env.DEV) // deny api and server page calls let denylist: undefined | RegExp[] if (import.meta.env.PROD) { - // const pwaIcons = /^\/(pwa-.*|maskable-icon|shortcuts\/.*|screenshots\/.*)\.(png|webp)/ denylist = [ /^\/api\//, /^\/login\//, @@ -46,21 +45,14 @@ if (import.meta.env.PROD) { /^\/emojis\//, // exclude sw: if the user navigates to it, fallback to index.html /^\/sw\.js$/, - // exclude web manifest icons - // pwaIcons, // exclude web manifest: has its own cache, if the user navigates to it, fallback to index.html - /// ^\/manifest-(.*)\.webmanifest$/, + /^\/manifest-(.*)\.webmanifest$/, ] // only cache pages and external assets on local build + start or in production // include webmanifest and images cache - /* registerRoute( - ({ request, sameOrigin, url }) => - sameOrigin && (( - request.destination === 'manifest' && url.pathname.startsWith('/manifest-') - ) || ( - request.destination === 'image' && pwaIcons.test(url.pathname) - )), + registerRoute( + ({ request, sameOrigin }) => sameOrigin && request.destination === 'manifest', new NetworkFirst({ cacheName: 'elk-webmanifest', // responses with a Vary: Accept-Encoding header @@ -73,7 +65,7 @@ if (import.meta.env.PROD) { new ExpirationPlugin({ maxEntries: 100 }), ], }), - ) */ + ) // include shiki cache registerRoute( ({ sameOrigin, url }) =>