diff --git a/astro.config.mjs b/astro.config.mjs index 82f606c..dbdcf58 100644 --- a/astro.config.mjs +++ b/astro.config.mjs @@ -1,5 +1,6 @@ import { defineConfig } from 'astro/config'; import sitemap from '@astrojs/sitemap'; +import AstroPWA from '@vite-pwa/astro'; import tailwindcss from '@tailwindcss/vite'; export default defineConfig({ @@ -14,6 +15,21 @@ export default defineConfig({ return item; }, }), + // Service worker → offline support + installable PWA. autoUpdate + outdated-cache + // cleanup so a redeploy never strands a visitor on a stale version. Reuses the + // existing public/site.webmanifest (manifest: false = don't generate another). + AstroPWA({ + registerType: 'autoUpdate', + manifest: false, + includeManifestIcons: false, + workbox: { + globPatterns: ['**/*.{html,css,js,svg,png,woff2,xml,txt,webmanifest}'], + cleanupOutdatedCaches: true, + clientsClaim: true, + skipWaiting: true, + }, + devOptions: { enabled: false }, + }), ], prefetch: { prefetchAll: true, defaultStrategy: 'viewport' }, vite: { plugins: [tailwindcss()] }, diff --git a/package.json b/package.json index 4e5efca..7e6765a 100644 --- a/package.json +++ b/package.json @@ -14,6 +14,7 @@ "@tailwindcss/vite": "^4.1.5", "tailwindcss": "^4.1.5", "@fontsource-variable/inter": "^5.2.5", + "@vite-pwa/astro": "^0.5.0", "sharp": "^0.34.5" } } diff --git a/src/layouts/Base.astro b/src/layouts/Base.astro index 57e0af5..d8cc47f 100644 --- a/src/layouts/Base.astro +++ b/src/layouts/Base.astro @@ -40,6 +40,9 @@ const { title, description, image, type, publishedTime, modifiedTime, tags, json