Hi all, I need some help with Cloudflare workers. I’m not a dev by any stretch of the imagination and use Webflow so no-code, but I’ve got a Webflow project where I need to squeeze every ounce of speed out of the site and I’m trying it on my domain first. I’ve got a Pro Cloudflare account set up for the project, but my problem is that Weblow keeps all the assets like css, fonts and most importantly images on assets.website-files.com and not my actual domain milkmoonstudio.com, so Cloudflare is not caching or applying any performance enhancements on the images etc. as assets.website-files.com is not part of my domain as you can see from the screenshot:
I contacted Cloudflare and they sent me this Cloudflare Workers script, but like I said, no code experience here, would anyone here be able to help me out with this stuff from Cloudflare:
/**
* An object with different URLs to fetch
* @param {Object} ORIGINS
*/
const ORIGINS = {
"starwarsapi.yourdomain.com": "swapi.dev",
"google.yourdomain.com": "www.google.com",
}
async function handleRequest(request) {
const url = new URL(request.url)
// Check if incoming hostname is a key in the ORIGINS object
if (url.hostname in ORIGINS) {
const target = ORIGINS[url.hostname]
url.hostname = target
// If it is, proxy request to that third party origin
return await fetch(url.toString(), request)
}
// Otherwise, process request as normal
return await fetch(request)
}
addEventListener("fetch", event => {
event.respondWith(handleRequest(event.request))
})
Any help would be much appreciated.