Skip to content

Commit

Permalink
feat: add workbox runtimeCaching config
Browse files Browse the repository at this point in the history
  • Loading branch information
YHhaoareyou committed May 19, 2022
1 parent c0585c1 commit 5d47e3c
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions root/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,40 @@ export default defineConfig(({ mode }) => {
},
],
},
workbox: {
runtimeCaching: [
{
urlPattern: ({ event }) => event.request.mode === "navigate",
handler: 'NetworkFirst',
options: {
cacheName: "navigate-cache",
fetchOptions: {
credentials: "same-origin",
},
},
},
{
urlPattern: /.*\.(?:js|ts|css)/,
handler: 'NetworkFirst',
options: {
cacheName: "js-css-cache",
fetchOptions: {
credentials: "same-origin",
},
},
},
{
urlPattern: /.*\.(?:png|jpg|jpeg|svg|gif|woff|woff2|eot|ttf|otf)/,
handler: "StaleWhileRevalidate",
options: {
cacheName: "image-font-cache",
fetchOptions: {
credentials: "same-origin",
},
},
},
],
},
}),
],
assetsInclude: ["**/*.png", "**/*.jpg", "**/*.svg"],
Expand Down

0 comments on commit 5d47e3c

Please sign in to comment.