feat: add excludeRoutes option
This commit is contained in:
parent
8e4083cb01
commit
c3df8b33da
3 changed files with 18 additions and 2 deletions
|
@ -14,6 +14,9 @@ export default defineConfig({
|
||||||
assetCachePrefix: 'cozy-reader',
|
assetCachePrefix: 'cozy-reader',
|
||||||
customRoutes: [
|
customRoutes: [
|
||||||
'/threads'
|
'/threads'
|
||||||
|
],
|
||||||
|
excludeRoutes: [
|
||||||
|
'/exclude'
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
]
|
]
|
||||||
|
|
13
index.js
13
index.js
|
@ -9,6 +9,7 @@ import { randomUUID } from "node:crypto";
|
||||||
* assetCachePrefix?: string,
|
* assetCachePrefix?: string,
|
||||||
* assetCacheVersionID?: string,
|
* assetCacheVersionID?: string,
|
||||||
* customRoutes?: Array<string>,
|
* customRoutes?: Array<string>,
|
||||||
|
* excludeRoutes?: Array<string,
|
||||||
* }} ServiceWorkerConfig
|
* }} ServiceWorkerConfig
|
||||||
* @typedef {import('astro').AstroIntegration} AstroIntegration
|
* @typedef {import('astro').AstroIntegration} AstroIntegration
|
||||||
*/
|
*/
|
||||||
|
@ -24,7 +25,8 @@ export default function serviceWorker(config) {
|
||||||
assetCachePrefix,
|
assetCachePrefix,
|
||||||
assetCacheVersionID = randomUUID(),
|
assetCacheVersionID = randomUUID(),
|
||||||
path: serviceWorkerPath,
|
path: serviceWorkerPath,
|
||||||
customRoutes = []
|
customRoutes = [],
|
||||||
|
excludeRoutes = []
|
||||||
} = config;
|
} = config;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -110,6 +112,11 @@ export default function serviceWorker(config) {
|
||||||
.filter(pathname => pathname !== '')
|
.filter(pathname => pathname !== '')
|
||||||
?? [];
|
?? [];
|
||||||
|
|
||||||
|
const _excludeRoutes = [
|
||||||
|
...excludeRoutes,
|
||||||
|
...excludeRoutes.map(route => `${route}/`)
|
||||||
|
];
|
||||||
|
|
||||||
assets = [...new Set([
|
assets = [...new Set([
|
||||||
...assets,
|
...assets,
|
||||||
..._routes,
|
..._routes,
|
||||||
|
@ -120,7 +127,9 @@ export default function serviceWorker(config) {
|
||||||
])].filter(asset => !!asset
|
])].filter(asset => !!asset
|
||||||
&& asset !== ''
|
&& asset !== ''
|
||||||
&& !asset.includes('404')
|
&& !asset.includes('404')
|
||||||
&& !asset.includes('index.html'));
|
&& !asset.includes('index.html')
|
||||||
|
&& !_excludeRoutes.includes(asset)
|
||||||
|
);
|
||||||
|
|
||||||
console.log('[astro-sw] Assets for caching:', assets);
|
console.log('[astro-sw] Assets for caching:', assets);
|
||||||
|
|
||||||
|
|
4
src/pages/exclude.astro
Normal file
4
src/pages/exclude.astro
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
---
|
||||||
|
---
|
||||||
|
|
||||||
|
exclude
|
Loading…
Reference in a new issue