Worker routing from dynamic subdomain to cached subdomain



hello sir.

I have 1 subdomains using cloudflare with orange-cloud and all image already cache by cloudflare on this subdomain, example:

I create 3 subdomains using cloudflare with orange-cloud and this is new subdomain don’t have cache on cloudflare, example:

on the 3 new subdomain it has a url that can access an image, and path url is same on privatecdn, example : => not yet cached on coudflare. => already cached on cloudflare.

this is my worker code:

addEventListener('fetch', event => {
async function fetchAndApply(request) {
  let privatecdn= "";
  var accessUrl = request.url.replace(/https?:\/\/cdn[0-9]\.example\.com/, privatecdn);
  return fetch(accessUrl, request);

which I want to ask, when the worker requests to “privatecdn” whether to retrieve data from the edge cache or retrieve data from the origin server?

@KentonVarda or @ryan please help me.


Hi @kputera410,

Requests you make with fetch() always go through cache. So your code will check for the file in edge cache before falling back to origin.