Browse Source

less PWA logs + allow main indexjs to be cached

pull/511/head
mrjvs 2 years ago
parent
commit
e7d6f4559e
  1. 4
      src/setup/pwa.ts
  2. 1
      vite.config.ts

4
src/setup/pwa.ts

@ -1,4 +1,3 @@ @@ -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; @@ -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({ @@ -23,7 +20,6 @@ registerSW({
});
if (resp?.status === 200) {
console.log(`SW update successfully triggered`);
await r.update();
}
}, intervalMS);

1
vite.config.ts

@ -42,6 +42,7 @@ export default defineConfig(({ mode }) => { @@ -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: [

Loading…
Cancel
Save