Hello
We have the following setup with image resize through workers: sub.domain.com/images/* → worker (image resize)
Is there any setting for reducing (caching) the number of request to sub.domain.com ?
In the billable usage, the number of image resize requests are 25% of the worker requests, so probably there is some caching in the middle, but I think that the responses from the workers with the resized images should be cached on the edge.
I haven’t used workers resize much and have not tested extensively, but I use a set-up with another party for resizing.
My Worker resizes, stores in KV and caches.
I have my workers set proper Cache-Control headers then use the below snippet which utilises the cache control headers.
async function handleRequest(event) {
const request = event.request
if(request.method == "GET") {
// Hook in to the cache and have any cache-control headers respected
const cache = caches.default;
let resp = await cache.match(request)
if (!resp) {
resp = await run(request)
// Use event waitUntil so we can send the response but
// script keeps executing until the response is saved in the cache
if(resp.status == 200) {
event.waitUntil(cache.put(request, resp.clone()))
}
}
return resp
}
const resp = await run(request)
return resp
}
async function run(request) {
// do resize
// set response Cache-Control headers i.e. Cache-Control: public, max-age=31536000
// return resp
}