feat:#5 added own service worker script for precache api during install

This commit is contained in:
Elmar Kresse
2024-08-13 20:41:45 +02:00
parent b848d26704
commit a22c7a1073
4 changed files with 44 additions and 48 deletions

View File

@@ -28,7 +28,13 @@ export default defineConfig({
mode: "development",
base: "/",
injectRegister: "auto",
includeAssets: ["favicon.ico", "apple-touch-icon.png", "mask-icon.svg"],
includeAssets: [
"favicon.ico",
"apple-touch-icon.png",
"mask-icon.svg",
"robots.txt",
"sitemap.xml"
],
manifest: {
name: "HTWKalender",
short_name: "HTWKalender",
@@ -81,47 +87,6 @@ export default defineConfig({
],
},
registerType: "autoUpdate",
workbox: {
globPatterns: ["**/*.{js,css,html,ico,png,svg,json,vue,txt,woff2}"],
cleanupOutdatedCaches: true,
runtimeCaching: [
{
urlPattern: ({ url }) => url.pathname.startsWith("/api/feed"),
method: "GET",
handler: "NetworkFirst",
options: {
cacheName: "calendar-feed-cache",
expiration: {
maxAgeSeconds: 12 * 60 * 60, // 12 hours
},
},
},
{
// Add the runtime caching strategy for /api/modules
urlPattern: ({url}) => url.pathname.startsWith('/api/modules'),
method: 'GET',
handler: 'NetworkFirst',
options: {
cacheName: 'modules-cache',
expiration: {
maxAgeSeconds: 24 * 60 * 60, // 1 day
},
},
},
{
urlPattern: /^https?.*/,
handler: "NetworkFirst",
options: {
cacheName: "https-calls",
expiration: {
maxEntries: 150,
maxAgeSeconds: 30 * 12 * 60 * 60, // 1 month
},
networkTimeoutSeconds: 10, // fall back to cache if api does not response within 10 seconds
},
},
],
},
devOptions: {
enabled: true,
/* when using generateSW the PWA plugin will switch to classic */
@@ -129,6 +94,7 @@ export default defineConfig({
navigateFallback: "index.html",
suppressWarnings: true,
},
strategies: "injectManifest",
}),
],
resolve: {