You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
import type { RuntimeCaching } from 'workbox-build';
|
|
|
|
/**
|
|
|
|
* workbox 匹配plugin的缓存
|
|
|
|
*/
|
|
|
|
export const workboxPluginEntryPattern =
|
|
|
|
/plugins\/com\.msgbyte(.*?)\/index\.js/;
|
|
|
|
|
|
|
|
export const workboxPluginDetailPattern =
|
|
|
|
/plugins\/com\.msgbyte\.(.*?)\/(\S+?)\-(\S*?)\.js/;
|
|
|
|
|
|
|
|
export function buildRuntimePluginJSResourceCacheGroup(
|
|
|
|
pattern: RegExp,
|
|
|
|
name: string,
|
|
|
|
expiration: number
|
|
|
|
): RuntimeCaching {
|
|
|
|
return {
|
|
|
|
urlPattern: pattern,
|
|
|
|
// urlPattern: ({ url }) => {
|
|
|
|
// // 使用自定义匹配函数而不是直接传是为了方便解决跨域资源的service worker存储
|
|
|
|
// // 否则需要填入完整的前缀以解决跨域匹配(workbox对此进行了特殊的处理)
|
|
|
|
// return pattern.test(url.pathname);
|
|
|
|
// },
|
|
|
|
handler: 'StaleWhileRevalidate' as const,
|
|
|
|
options: {
|
|
|
|
cacheName: name,
|
|
|
|
expiration: {
|
|
|
|
maxAgeSeconds: expiration,
|
|
|
|
},
|
|
|
|
cacheableResponse: {
|
|
|
|
// 只缓存js, 防止404后台直接fallback到html
|
|
|
|
headers: {
|
|
|
|
'content-type': 'application/javascript; charset=utf-8',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|