Can a workers output be cached in cdn with page rules?


Hi there -

I have seen similar posts but not sure how page rules and the output of a worker work. Supposed I have a worker function

async function handleApiRequest(request) {
let cache = caches.default
let response = await cache.match(request)

const responseInit = {
  headers: {'Content-Type': 'application/json'},
const combined = {
  tim: new Date()
response = new Response(JSON.stringify(combined), responseInit)
response.headers.set("Cache-Control", "public, max-age=1");

event.waitUntil(cache.put(request, response.clone()))


1 Like

Adding #developers:workers tag speeds up getting an answer to your question.

1 Like

Depends on the output of your worker. If it depends to an external api call, caching that would make it faster to respond. But if it’s just pure execution, I think it’s going to be the same with a few milliseconds of discrepancy.