Cache resources

This commit is contained in:
momo5502
2025-09-06 20:40:44 +02:00
parent 5997ec55ac
commit 9be8e27001
2 changed files with 33 additions and 0 deletions

View File

@@ -7,6 +7,7 @@
<link
rel="icon"
type="image/png"
crossorigin="anonymous"
href="https://momo5502.com/emulator/pinata.png"
/>

View File

@@ -3,9 +3,30 @@ import tailwindcss from "@tailwindcss/vite";
import { defineConfig } from "vite";
import { VitePWA } from "vite-plugin-pwa";
import react from "@vitejs/plugin-react";
import { RuntimeCaching } from "workbox-build";
const mb = 1024 ** 2;
function generateExternalCache(
pattern: string | RegExp,
name: string,
): RuntimeCaching {
return {
urlPattern: pattern,
handler: "CacheFirst",
options: {
cacheName: name,
expiration: {
maxEntries: 10,
maxAgeSeconds: 60 * 60 * 24 * 365, // <== 365 days
},
cacheableResponse: {
statuses: [0, 200],
},
},
};
}
// https://vite.dev/config/
export default defineConfig({
plugins: [
@@ -19,6 +40,17 @@ export default defineConfig({
},
workbox: {
maximumFileSizeToCacheInBytes: 100 * mb,
globPatterns: ["**/*.{js,css,html,woff,woff2}"],
runtimeCaching: [
generateExternalCache(
/^https:\/\/momo5502\.com\/.*/i,
"momo5502-cache",
),
generateExternalCache(
/^https:\/\/img\.youtube\.com\/.*/i,
"youtube-img-cache",
),
],
},
}),
],