A custom CDN implementation using Cloudflare Workers and R2 storage to serve files from GitHub repositories. Supports versioning, minification, and compression.
- 🌍 Global CDN via Cloudflare's edge network
- 📦 Serves files from public and private GitHub repositories
- 🏷️ Version control support (releases and commit hashes)
- 🔄 Automatic minification for JS and CSS files
- 💾 R2 caching for improved performance
- 🗜️ Automatic compression for script/link requests
- 👀 Browser-friendly file previews
- 🔄 JSDelivr URL conversion support
- 🚀 Pre-caching option for faster delivery
- Create a Cloudflare account if you don't have one
- Install Wrangler CLI:
npm install -g wrangler
- Login to Cloudflare via Wrangler:
wrangler login
-
Create an R2 bucket in Cloudflare Dashboard:
- Go to R2 section
- Click "Create bucket"
- Name it
dxd-cdn(or update wrangler.toml if using a different name)
-
Update wrangler.toml with your bucket details (already configured if using default name)
-
Create a GitHub Personal Access Token:
- Go to GitHub.com → Settings → Developer Settings → Personal Access Tokens → Tokens (classic)
- Click "Generate new token (classic)"
- Select scopes:
- For public repos only:
public_repo - For private repos:
repo(full control)
- For public repos only:
- Copy the generated token
-
Add the token to your worker:
wrangler secret put GITHUB_TOKEN
When prompted, paste your GitHub token
-
Add your domain in Cloudflare Dashboard:
- Go to Workers & Pages
- Select your worker
- Click "Add Custom Domain"
- Follow the prompts to add your domain
-
Update wrangler.toml with your domain:
routes = [ { pattern = "your-domain.com", custom_domain = true } ]
- Clone this repository
- Install dependencies:
npm install
- Deploy to Cloudflare:
npm run deploy
https://your-domain.com/[repo-name]/[version]/[file-path]
Where:
repo-name: Name of your GitHub repositoryversion: Can be:- A specific release tag (e.g.,
v1.0.0) - A commit hash (full or short, e.g.,
a1b2c3d)
- A specific release tag (e.g.,
file-path: Path to the file in the repository
# Specific version
https://your-domain.com/my-project/v1.0.0/dist/script.js
# Specific commit
https://your-domain.com/my-project/a1b2c3d/dist/script.js
# Minified version (add .min before extension)
https://your-domain.com/my-project/v1.0.0/dist/script.min.js
Visit https://your-domain.com/convert for a web interface that provides:
- Convert GitHub URLs to CDN URLs
- Convert JSDelivr URLs to CDN URLs
- Select specific versions or commit hashes
- Toggle minification
- Pre-cache files for faster delivery
- One-click copying with ⌘C/Ctrl+C
- Paste a GitHub file URL
- Choose between version or commit hash
- Toggle minification if needed
- Enable pre-caching if desired
- Copy the generated CDN URL
- Paste a JSDelivr URL
- The version/commit from the JSDelivr URL will be preserved
- Toggle minification if needed
- Enable pre-caching if desired
- Copy the generated CDN URL
- Run locally:
npm run dev
- Make changes to
src/index.js - Deploy changes:
npm run deploy
GITHUB_TOKEN: GitHub Personal Access Token (required)- No other environment variables needed
- Minification only supported for JS and CSS files
- R2 storage limits based on your Cloudflare plan
- GitHub API rate limits apply when fetching new files
- Private repos require
reposcope GitHub token