less PWA logs + allow main indexjs to be cached

This commit is contained in:
mrjvs 2023-12-06 19:37:51 +01:00
parent bcb2e02b85
commit e7d6f4559e
2 changed files with 1 additions and 4 deletions

View File

@ -1,4 +1,3 @@
/* eslint-disable no-console */
import { registerSW } from "virtual:pwa-register";
const intervalMS = 60 * 60 * 1000;
@ -6,10 +5,8 @@ const intervalMS = 60 * 60 * 1000;
registerSW({
immediate: true,
onRegisteredSW(swUrl, r) {
console.log(`SW registered at: ${swUrl}`);
if (!r) return;
setInterval(async () => {
console.log(`attempting SW update`);
if (!(!r.installing && navigator)) return;
if ("connection" in navigator && !navigator.onLine) return;
@ -23,7 +20,6 @@ registerSW({
});
if (resp?.status === 200) {
console.log(`SW update successfully triggered`);
await r.update();
}
}, intervalMS);

View File

@ -42,6 +42,7 @@ export default defineConfig(({ mode }) => {
disable: process.env.VITE_PWA_ENABLED !== "yes",
registerType: "autoUpdate",
workbox: {
maximumFileSizeToCacheInBytes: 4000000, // 4mb
globIgnores: ["**ping.txt**"]
},
includeAssets: [