Skip to content

Commit

Permalink
Service worker tweaks including auto reload
Browse files Browse the repository at this point in the history
  • Loading branch information
microbit-robert committed Apr 25, 2024
1 parent d1c2963 commit a2dcb6f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
3 changes: 3 additions & 0 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import { StrictMode } from "react";
import { createRoot } from "react-dom/client";
import App from "./App";
import reportWebVitals from "./reportWebVitals";
import { registerSW } from "virtual:pwa-register";

registerSW({ immediate: true });

const root = createRoot(document.getElementById("root")!);
root.render(
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true
"noFallthroughCasesInSwitch": true,
"types": ["vite-plugin-pwa/client"]
},
"include": ["src"],
"references": [{ "path": "./tsconfig.node.json" }]
Expand Down
7 changes: 2 additions & 5 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,6 @@ export default defineConfig(({ mode }) => {
VitePWA({
registerType: "autoUpdate",
workbox: {
// A better chance of the runtime caches taking affect on first visit.
clientsClaim: true,
skipWaiting: true,
cleanupOutdatedCaches: true,
// Ignore all language related assets and cache these at runtime instead.
globIgnores: [
"**/{pyright-locale*.js,typeshed*.js,search.worker*.js,ui*.js}",
Expand Down Expand Up @@ -112,7 +108,8 @@ export default defineConfig(({ mode }) => {
},
},
{
urlPattern: /.*(?:pyright-locale|search\.worker|typeshed).*.js/,
urlPattern:
/.*(?:pyright-locale|search\.worker|typeshed|ui\.).*.js/,
handler: "NetworkFirst",
options: {
cacheName: "lang-cache",
Expand Down

0 comments on commit a2dcb6f

Please sign in to comment.