@codewithjonam
Blog
Sharing knowledge through the art of wordsHow to use GitHub as CDN for assets
June 17, 2024While building my portfolio site, embedding images and code snippets into my blog posts was bloating the source code and would likely turn into a tangled mess over time.
Hence, I was looking for a free CDN service to handle these assets and found that we can use GitHub as a CDN for hosting assets.
Here's a step-by-step guide:
Using GitHub as a CDN for your assets is a great solution for developers looking for a free and reliable hosting option. However, please note that this will not replace dedicated CDN services for high-traffic websites. This is a great alternative for smaller projects, personal websites, or development purposes.
I hope this was helpful!
Hence, I was looking for a free CDN service to handle these assets and found that we can use GitHub as a CDN for hosting assets.
Here's a step-by-step guide:
- Go to GitHub and login to your account
- Create a new repository by clicking on the New button
- Provide Repository name (Ex:
), select Public and click on Create repositorymy-assets-cdn
- Next, upload assets that you want to serve via the CDN
- Click on the link uploading an existing file
- Upload file, add commit message and click on Commit changes
- Now, you can access the uploaded file using the below url
- Replace
,{username}
,{repositoryname}
and{branchname}
accordingly{filename}
- For the file that i uploaded earlier, the url will be as below
- You can even access files under folders as below
1https://cdn.jsdelivr.net/gh/{username}/{repositoryname}@{branchname}/{filename}
1https://cdn.jsdelivr.net/gh/thejonamreddy/my-assets-cdn@main/Manoj Kumar Reddy P Resume.pdf
1https://cdn.jsdelivr.net/gh/{username}/{repositoryname}@{branchname}/{foldername}/{filename}
Using GitHub as a CDN for your assets is a great solution for developers looking for a free and reliable hosting option. However, please note that this will not replace dedicated CDN services for high-traffic websites. This is a great alternative for smaller projects, personal websites, or development purposes.
I hope this was helpful!