feat(cdn): cdn完善

这个提交包含在:
2025-08-17 00:01:58 +08:00 未验证
父节点 8209708ff5
当前提交 4922a80f41
修改 5 个文件,包含 34 行新增10 行删除
+5 -3
查看文件
@@ -4,7 +4,7 @@
let config = {
cdnUrl: 'https://cdn.fillcode.com/',
serviceWorkerUrl: '/__static/sw-cdn.js',
staticRegex: /\.(js|css|png|jpg|jpeg|gif|svg|webp|woff|woff2|ttf|ico)$/,
staticRegex: /(.*\.(css|js|png|jpg|jpeg|gif|svg|webp|ico|woff|woff2|ttf|eot)|avatars[^/]+)$/,
debug: false,
}
@@ -54,17 +54,19 @@ async function handleStaticResource(request, url) {
if (config.debug) console.log('PWA-CDN:', url.href, '->', targetUrl)
try {
// 创建新请求,保留原始缓存策略
// 创建新请求
const newRequest = new Request(targetUrl, {
...request,
mode: 'cors',
credentials: 'include',
redirect: 'manual',
})
// 请求目标域名,浏览器会自动处理缓存
const response = await fetch(newRequest)
if (!response.ok) throw new Error('Target domain response not ok: ' + response.status)
// 当遇到非2XX返回时 全部回退原始请求 防止鉴权、重定向等问题
if (response.status < 200 || response.status >= 300) throw new Error('PWA-CDN: Non-2xx response detected')
return response
} catch (error) {