123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202 |
- module.exports = [
- {
- urlPattern: /^https:\/\/fonts\.(?:gstatic)\.com\/.*/i,
- handler: 'CacheFirst',
- options: {
- cacheName: 'google-fonts-webfonts',
- expiration: {
- maxEntries: 4,
- maxAgeSeconds: 365 * 24 * 60 * 60,
- },
- },
- },
- {
- urlPattern: /^https:\/\/fonts\.(?:googleapis)\.com\/.*/i,
- handler: 'StaleWhileRevalidate',
- options: {
- cacheName: 'google-fonts-stylesheets',
- expiration: {
- maxEntries: 4,
- maxAgeSeconds: 7 * 24 * 60 * 60,
- },
- },
- },
- {
- 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,
- },
- },
- },
- {
- urlPattern: /\.(?:jpg|jpeg|gif|png|svg|ico|webp)$/i,
- handler: 'StaleWhileRevalidate',
- options: {
- cacheName: 'static-image-assets',
- expiration: {
- maxEntries: 64,
- maxAgeSeconds: 24 * 60 * 60,
- },
- },
- },
- {
- urlPattern: /\/_next\/image\?url=.+$/i,
- handler: 'StaleWhileRevalidate',
- options: {
- cacheName: 'next-image',
- expiration: {
- maxEntries: 64,
- maxAgeSeconds: 24 * 60 * 60,
- },
- },
- },
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- {
- urlPattern: /\.(?:mp4)$/i,
- handler: 'CacheFirst',
- options: {
- rangeRequests: true,
- cacheName: 'static-video-assets',
- expiration: {
- maxEntries: 32,
- maxAgeSeconds: 24 * 60 * 60,
- },
- },
- },
- {
- urlPattern: /\.(?:js)$/i,
- handler: 'StaleWhileRevalidate',
- options: {
- cacheName: 'static-js-assets',
- expiration: {
- maxEntries: 32,
- maxAgeSeconds: 24 * 60 * 60,
- },
- },
- },
- {
- urlPattern: /\.(?:css|less)$/i,
- handler: 'StaleWhileRevalidate',
- options: {
- cacheName: 'static-style-assets',
- expiration: {
- maxEntries: 32,
- maxAgeSeconds: 24 * 60 * 60,
- },
- },
- },
- {
- urlPattern: /\/_next\/data\/.+\/.+\.json$/i,
- handler: 'StaleWhileRevalidate',
- options: {
- cacheName: 'next-data',
- expiration: {
- maxEntries: 32,
- maxAgeSeconds: 24 * 60 * 60,
- },
- },
- },
- {
- urlPattern: /\.(?:json|xml|csv)$/i,
- handler: 'NetworkFirst',
- options: {
- cacheName: 'static-data-assets',
- expiration: {
- maxEntries: 32,
- maxAgeSeconds: 24 * 60 * 60,
- },
- },
- },
- {
- urlPattern: ({ url }) => {
- const isSameOrigin = self.origin === url.origin;
- if (!isSameOrigin) return false;
- const { pathname } = url;
-
-
-
- if (pathname.startsWith('/api/auth/')) return false;
- if (pathname.startsWith('/api/')) return true;
- return false;
- },
- handler: 'NetworkFirst',
- method: 'GET',
- options: {
- cacheName: 'apis',
- expiration: {
- maxEntries: 16,
- maxAgeSeconds: 24 * 60 * 60,
- },
- networkTimeoutSeconds: 10,
- },
- },
- {
- urlPattern: ({ url }) => {
- const isSameOrigin = self.origin === url.origin;
- if (!isSameOrigin) return false;
- const { pathname } = url;
- if (pathname.startsWith('/api/')) return false;
- return true;
- },
- handler: 'NetworkFirst',
- options: {
- cacheName: 'others',
- expiration: {
- maxEntries: 32,
- maxAgeSeconds: 24 * 60 * 60,
- },
- networkTimeoutSeconds: 10,
- },
- },
- {
- urlPattern: ({ url }) => {
- const { pathname } = url;
- const isSameOrigin = self.origin === url.origin;
-
- return !isSameOrigin && !pathname.endsWith('.mp3');
- },
- handler: 'NetworkFirst',
- options: {
- cacheName: 'cross-origin',
- expiration: {
- maxEntries: 32,
- maxAgeSeconds: 60 * 60,
- },
- networkTimeoutSeconds: 10,
- },
- },
- ];
|