Only "purge everything" option works to clear cache

What is the name of the domain?

What is the issue you’re encountering

I am using a Worker that grabs the page or asset from an origin site and serves it to my production site. When I update a file on my server, I can only get the updated version of it on the production site by purging the entire cache. Purging by the host name also worked for me.

What steps have you taken to resolve the issue?

So let’s say this example file lives at www.example.com/subdir/styles.css and my Cloudflare Worker caches to the default. These custom purge options did not work for me:

This sounds like your worker is fetching a slightly different path from what you’re attempting to purge.

Here’s a simplified version of my Worker:

const ORIGIN = "https://origin.example.com"

async function handleRequest(request, ctx) {
	const url = new URL(request.url)
	const pathname = url.pathname
	const pathWithParams = pathname + url.search

	if ( pathname.match(/\.(css|js|jpg|jpeg|png|gif|svg|webp|bmp|tiff|eps|pdf|txt|ico|webmanifest|xml|yml|json|log|lock|md|scss|map)$/) ) {
		console.log('is a static asset:', pathname);
		return retrieveStatic(request, pathWithParams, ctx)
	} else {
		console.log('process page:', pathname);
		return forwardRequest(request, url)
	}
}

async function retrieveStatic(request, pathname, ctx) {
	let response = await caches.default.match(request)
	if (!response) {
		response = await fetch(`${ORIGIN}${pathname}`)
		ctx.waitUntil(caches.default.put(request, response.clone()))
	}
	return response
}

async function forwardRequest(request, pathWithSearch) {
	const originRequest = new Request(request)
	return await fetch(`${ORIGIN}${pathWithSearch}`, originRequest)
}

export default {
	async fetch(request, env, ctx) {
		return handleRequest(request, ctx);
	}
}

Let’s say my domain example.com has DNS controlled by Cloudflare and is proxied through Cloudflare and the site www.example.com serves this worker that fetches https://origin.example.com (as demonstrated above). I’m trying to do a custom purge to clear https://www.example.com/assets/style.css from the cache but it does not work. Any idea what I’m doing wrong here? I tried purging URLs https://www.example.com/assets/style.css and https://www.example.com/assets/style.css and the workers.dev domain https://worker-name.example.workers.dev/assets/style.css but it doesn’t seem to be taking.