async function fetchJquery(event, request) {
const cache = caches.default;
let response = await fetch(request);
response.headers.append('Cache-Control', 's-maxage=10');
event.waitUntil(cache.put(request, response.clone()));
response.headers.append('x-edgefunctions-cache', 'miss');
return response;
}
async function handleEvent(event) {
const request = new Request('https://static.cloudcachetci.com/qcloud/main/scripts/release/common/vendors/jquery-3.2.1.min.js');
const cache = caches.default;
try {
let response = await cache.match(request);
if (!response) {
return fetchJquery(event, request);
}
response.headers.append('x-edgefunctions-cache', 'hit');
return response;
} catch (e) {
await cache.delete(request);
return fetchJquery(event, request);
}
}
addEventListener('fetch', (event) => {
event.respondWith(handleEvent(event));
});
本页内容是否解决了您的问题?