From c3df8b33daa3dc0ef1833994a37c73abe6543df3 Mon Sep 17 00:00:00 2001 From: ayoayco Date: Fri, 16 Aug 2024 13:17:18 +0200 Subject: [PATCH] feat: add excludeRoutes option --- astro.config.mjs | 3 +++ index.js | 13 +++++++++++-- src/pages/exclude.astro | 4 ++++ 3 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 src/pages/exclude.astro diff --git a/astro.config.mjs b/astro.config.mjs index a685145..c87c314 100644 --- a/astro.config.mjs +++ b/astro.config.mjs @@ -14,6 +14,9 @@ export default defineConfig({ assetCachePrefix: 'cozy-reader', customRoutes: [ '/threads' + ], + excludeRoutes: [ + '/exclude' ] }) ] diff --git a/index.js b/index.js index 491f924..53c46a5 100644 --- a/index.js +++ b/index.js @@ -9,6 +9,7 @@ import { randomUUID } from "node:crypto"; * assetCachePrefix?: string, * assetCacheVersionID?: string, * customRoutes?: Array, + * excludeRoutes?: Array pathname !== '') ?? []; + const _excludeRoutes = [ + ...excludeRoutes, + ...excludeRoutes.map(route => `${route}/`) + ]; + assets = [...new Set([ ...assets, ..._routes, @@ -120,7 +127,9 @@ export default function serviceWorker(config) { ])].filter(asset => !!asset && asset !== '' && !asset.includes('404') - && !asset.includes('index.html')); + && !asset.includes('index.html') + && !_excludeRoutes.includes(asset) + ); console.log('[astro-sw] Assets for caching:', assets); diff --git a/src/pages/exclude.astro b/src/pages/exclude.astro new file mode 100644 index 0000000..ae9411d --- /dev/null +++ b/src/pages/exclude.astro @@ -0,0 +1,4 @@ +--- +--- + +exclude \ No newline at end of file