June 25, 2020
Use any GitHub repo as a CDN
Have you ever thought how use your own GitHub or anyone else’s GitHub as a CDN to link into your project? Well, check here how to do this!

By Ricardo Zambon
Recently I discovered jsDelivr, which is a service that allows transform any GitHub repository into a CDN, and the better, without fees!
How it works:
- The URL format is
[http://cdn.jsdelivr.net/gh/{usuario}/{repo}/](http://cdn.jsdelivr.net/gh/{usuario}/{repo}/,), where you replace{user}by the repository owner from GitHub and{repo}by the repository name. - Append to the URL the file path that you want access inside the repository, for example, for my project the file was in
/images/character, so, would be something like this: http://cdn.jsdelivr.net/gh/ricardozambon/AluraImersaoGameDev/src/images/character/running.png
The jsDelivr also allows loading files from a specific branch, if your repository has more branches.
http://cdn.jsdelivr.net/gh/ricardozambon/AluraImersaoGameDev@latest/src/images/character/running.png
http://cdn.jsdelivr.net/gh/ricardozambon@master/AluraImersaoGameDev/src/images/character/running.png
If the file is a CSS / JSS, you can also add the suffix .min to load the minified version (If you don't have it, there is no problem, it will generate one for you!).
http://cdn.jsdelivr.net/gh/ricardozambon/AluraImersaoGameDev@master/src/scripts/game/animate.min.js
And at least, something that will definitely help you if you need load several separated files, you can include them into a single link using the same pattern and splitting them using commas:
If you are already impressed by this free service (I was), jsDelivr additionally provides support for NPM and Wordpress files, just need change the prefix of the URL:
GitHub: https://cdn.jsdelivr.net/gh/...
NPM: https://cdn.jsdelivr.net/npm/...
WordPress: https://cdn.jsdelivr.net/wp/...