Skip to content

Commit

Permalink
fix: runtime caching
Browse files Browse the repository at this point in the history
  • Loading branch information
rayriffy committed Jan 5, 2024
1 parent 06d9617 commit 9b920a8
Showing 1 changed file with 5 additions and 26 deletions.
31 changes: 5 additions & 26 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,37 +50,16 @@ const config: UserConfig = {
runtimeCaching: [
// optimized image
{
urlPattern: /\/api\/_image\?url=.+$/i,
urlPattern: /\/api\/_image.+$/i,
handler: 'CacheFirst',
options: {
cacheName: 'riffyh-svelte-optimized-image',
cacheName: 'urami-image',
expiration: {
maxEntries: 1000,
maxAgeSeconds: 60 * 60 * 24 * 7, // 7 days
},
},
},
{
urlPattern: /^https:\/\/fonts\.(?:googleapis|gstatic)\.com\/.*/i,
handler: 'CacheFirst',
options: {
cacheName: 'google-fonts',
expiration: {
maxEntries: 4,
maxAgeSeconds: 365 * 24 * 60 * 60, // 365 days
},
},
},
{
urlPattern: /\.(?:eot|otf|ttc|ttf|woff|woff2|font.css)$/i,
handler: 'StaleWhileRevalidate',
options: {
cacheName: 'static-font-assets',
expiration: {
maxEntries: 4,
maxAgeSeconds: 7 * 24 * 60 * 60, // 7 days
},
},
},
{
urlPattern: /\.(?:jpg|jpeg|gif|png|svg|ico|webp)$/i,
handler: 'StaleWhileRevalidate',
Expand All @@ -98,7 +77,7 @@ const config: UserConfig = {
options: {
cacheName: 'static-js-assets',
expiration: {
maxEntries: 32,
maxEntries: 64,
maxAgeSeconds: 24 * 60 * 60, // 24 hours
},
},
Expand Down Expand Up @@ -132,7 +111,7 @@ const config: UserConfig = {
options: {
cacheName: 'apis',
expiration: {
maxEntries: 16,
maxEntries: 200,
maxAgeSeconds: 24 * 60 * 60, // 24 hours
},
networkTimeoutSeconds: 10, // fall back to cache if api does not response within 10 seconds
Expand Down

0 comments on commit 9b920a8

Please sign in to comment.