https://github.com/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.
https://github.com/tm9657/cloudflare-images-r2-cache
cache cloudflare images r2
Last synced: about 1 month ago
JSON representation
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.
- Host: GitHub
- URL: https://github.com/tm9657/cloudflare-images-r2-cache
- Owner: TM9657
- License: other
- Created: 2023-05-20T23:45:47.000Z (almost 2 years ago)
- Default Branch: master
- Last Pushed: 2023-05-21T16:19:42.000Z (almost 2 years ago)
- Last Synced: 2025-03-26T11:44:52.507Z (about 2 months ago)
- Topics: cache, cloudflare, images, r2
- Language: TypeScript
- Homepage: https://tm9657.de
- Size: 52.7 KB
- Stars: 22
- Watchers: 0
- Forks: 5
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# 📸️ 📦️ 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=&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](https://kwirk.io?ref=github) (**Text Editor** with **AI integration**, privacy focus and offline support) [Free]