TM9657 / cloudflare-images-r2-cache

Using Cloudflare Images + R2 Storage to add a caching layer for variants (looking at you 1$ / 100k deliveries). The first time an image is requested is redirected to images, after that the image is stored in r2. Future requests are redirected to R2.

Home Page:https://tm9657.de

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

📸️ 📦️ Cloudflare Images Buffer

Using Cloudflare Images + R2 Storage to add a caching layer for variants (looking at you 1$ / 100k deliveries). The first time an image is requested is redirected to images, after that the image is stored in r2. Future requests are redirected to R2.

📦️ Installation

0. clone the repo
1. pnpm install
2. pnpm run initialize
3. pnpm run build

❤️ Who is this for?

The default pricing is absolute great for bigger images (over 100kb) that are not delivered often. However for smaller images (profile pictures) that are requested frequently, the delivery fee can become costly.

This project makes it easier to handle those cases. If you do not have lots of smaller often requested images, you will pay extra r2 and worker fees with this approach.

🍎 Notes

You can access your images by calling the provided worker API like that: https://endpoint?id=<id>&variant=<variant> (GET Request)

To delete a cached image variants just call the endpoint with a DELETE request (you can ommit the variant parameter) and provide the header "authorization" with your secret. (generated on initialization)

Images above your limit size will be stored as 1 byte. The endpoint will lookup the size with a head request to R2 (class B action) and determine if the request will be redirected to the endpoint or the cdn.

A Custom URL based on your public bucket URL is used for the images endpoint.


Provided by TM9657 GmbH with ❤️

Check out some of our products:

  • Kwirk.io (Text Editor with AI integration, privacy focus and offline support) [Free]

About

Using Cloudflare Images + R2 Storage to add a caching layer for variants (looking at you 1$ / 100k deliveries). The first time an image is requested is redirected to images, after that the image is stored in r2. Future requests are redirected to R2.

https://tm9657.de

License:Other


Languages

Language:TypeScript 98.3%Language:JavaScript 1.7%