diff --git a/astro.config.mjs b/astro.config.mjs index c030e97..f9cd856 100644 --- a/astro.config.mjs +++ b/astro.config.mjs @@ -3,6 +3,7 @@ import { defineConfig } from "astro/config"; import node from "@astrojs/node"; import serviceWorker from "./packages/index.js"; +import { Strategies } from "./packages/strategies/index.js"; export default defineConfig({ output: "hybrid", @@ -32,6 +33,9 @@ export default defineConfig({ const sw = await navigator.serviceWorker.getRegistration(); console.log('>>> registrered', sw) } + }, + experimental: { + strategy: Strategies.CacheRevalidatePreloadFallback, } }) ] diff --git a/packages/index.js b/packages/index.js index 8bd043b..79a6335 100644 --- a/packages/index.js +++ b/packages/index.js @@ -33,6 +33,14 @@ const ASTROSW = '@ayco/astro-sw'; * unsupported?: () => void, * afterRegistration?: () => void, * } + * experimental?: { + * strategy?: { + * fetchFn: () => void, + * installFn: () => void, + * activateFn: () => void, + * waitFn: () => void, + * } + * } * }} options * @returns {AstroIntegration} */ diff --git a/packages/strategies/CacheRevalidatePreloadFallback.js b/packages/strategies/CacheRevalidatePreloadFallback.js index 43e630f..8224319 100644 --- a/packages/strategies/CacheRevalidatePreloadFallback.js +++ b/packages/strategies/CacheRevalidatePreloadFallback.js @@ -142,7 +142,7 @@ const fetchFn = (event) => { const waitFn = (event) => {} -export default { +export const CacheRevalidatePreloadFallback = { fetchFn, installFn, activateFn, diff --git a/packages/strategies/index.js b/packages/strategies/index.js new file mode 100644 index 0000000..4a1ef97 --- /dev/null +++ b/packages/strategies/index.js @@ -0,0 +1,5 @@ +import { CacheRevalidatePreloadFallback } from "./CacheRevalidatePreloadFallback.js"; + +export const Strategies = { + CacheRevalidatePreloadFallback +} \ No newline at end of file