A Next.js application that serves GitHub and Gist content as a CDN. This easy-to-use tool allows you to quickly convert GitHub repository files and Gists into CDN URLs for direct access.
- Serve GitHub repository files directly via CDN URL
- Serve Gist content directly via CDN URL
- Memory-efficient caching for faster delivery
- Purge cached content when needed
- Modern, responsive UI with excellent user experience
https://github.com/{username}/{repo}/{branch}/{path}
Example:
https://github.com/p32929/p32929.github.io/blob/react/README.md
https://gist.github.com/{username}/{gistId}
Example:
https://gist.github.com/p32929/7a2375cf2eb3d2986a741d7dc293a4c8
Here are 5 practical examples of when GitHub CDN is useful:
-
Serving JavaScript Libraries in Web Pages
<script src="https://your-cdn-domain.com/github/username/repo/branch/path/to/script.js"></script>
-
Loading CSS Stylesheets
<link rel="stylesheet" href="https://your-cdn-domain.com/github/username/repo/branch/path/to/styles.css">
-
Embedding Code Snippets from Gists
<script src="https://your-cdn-domain.com/gist/username/gistId"></script>
-
Fetching JSON Configuration Files
fetch('https://your-cdn-domain.com/github/username/repo/branch/path/to/config.json') .then(response => response.json()) .then(data => console.log(data));
-
Serving Text Content and Documentation
<iframe src="https://your-cdn-domain.com/github/username/repo/branch/path/to/documentation.md" width="100%" height="500px"></iframe>
GitHub CDN has some limitations you should be aware of:
-
Binary Files: Not optimized for serving large binary files or applications.
-
Image Files: While technically possible, the CDN is not optimized for image delivery. Consider using dedicated image hosting services for better performance.
-
Rate Limiting: Subject to GitHub API rate limits if you don't provide a GitHub token.
-
Private Repositories: Does not support private repositories unless you provide authentication.
-
Frequent Updates: If your content changes frequently, you may need to manually purge the cache.
- Node.js 18.x or later
- npm or yarn
- Clone the repository
git clone https://github.com/p32929/ghcdn.git
cd ghcdn
- Install dependencies:
npm install
# or
yarn
- Start the development server:
npm run dev
# or
yarn dev
- Open http://localhost:3000 in your browser
Create a .env
file with the following variables:
GITHUB_TOKEN=your_github_token # Optional, but recommended for higher rate limits
Deploy GitHub CDN with one click to your preferred platform:
- Cloudflare Pages: Fork the repo and import it in Cloudflare Pages
- Fly.io: Run
fly launch
in the cloned repository - Cyclic: Import from Cyclic Dashboard
- Northflank: Create project from Northflank
- Deta Space: Use
space push
after installing Space CLI - Replit: Import directly from Replit
- Glitch: Remix on Glitch
- Surge.sh: Deploy with
surge
after building locally - GitHub Pages: Use GitHub Actions for deployment (static export required)
- Azure Static Web Apps: Deploy via Azure Portal
All platforms will auto-detect Next.js and apply appropriate build settings. No additional configuration files needed!
Run with Docker:
docker build -t ghcdn .
docker run -p 3000:3000 -e GITHUB_TOKEN=your_token ghcdn
Variable | Required | Description |
---|---|---|
GITHUB_TOKEN |
No | GitHub personal access token for higher API rate limits (Create token) |
Most platforms will prompt you to add environment variables during deployment.
MIT License
Copyright (c) 2025 Fayaz Bin Salam
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.