概述条件缓存提升策略可控性。本文展示按路径与响应头进行缓存的实现。代理与缓存self.addEventListener('fetch', event => { const url = new URL(event.request.url); if (url.pathname.startsWith('/api/cacheable')) { event.respondWith((async () => { const res = await fetch(event.request); const cacheControl = res.headers.get('Cache-Control') || ''; if (!cacheControl.includes('no-store')) { const cache = await caches.open('api-v1'); await cache.put(event.request, res.clone()); } return res; })()); } });

点赞(0) 打赏

评论列表 共有 0 条评论

暂无评论
立即
投稿

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部
2.062139s