Use this to:
- Add a custom domain to your Cloudinary account
- Cache your images, so you don't run up your Cloudinary bandwidth
This is made for Cloudinary, but should work for any CDN. For instance, you can proxy Backblaze B2 files with Cloudflare. The bandwidth between the two is free, so you are really only paying Backblaze to hold onto your assets.
- Run
npm install
- Rename
wrangler.toml.example
towrangler.toml
- In
wrangler.toml
, fill in the Account ID and Zone ID found on your cloudflare domain name main page. - Fill in your Cloudinary cloud name in the environmental variables in
wrangler.toml
- Change
route = "images.yourdomain.com/*"
inwranglerfile.toml
to match your domain. - Deploy the sucker with:
npx wrangler dev
to test it. This will run it on localhostnpx wrangler deploy
to push to your custom domain
- In the Cloudflare Workers dashboard, add your domain to the worker on Settings > Domains & Routes > Add Custom Domain
Say you have a URL that looks like this:
https://res.cloudinary.com/wesbos/image/upload/v1612297289/ARG-poster_cexeys.jpg
Replace the res.cloudinary.com/wesbos/image
part with images.yourdomain.com/CLOUDNAME
.
So mine looks like this:
https://images.wesbos.com/upload/v1612297289/ARG-poster_cexeys.jpg
This should still work with all the fetching, and URL transforms.
You can verify that your images are being cached by looking for the cf-cache-status HIT
response header in your dev tools network tab. This will only show up the second time you request it.