Use GitHub for hosting JS and CSS files

How to use your CSS and JS files direcly from GitHub

  • Share

Recently I've started JQuery plugin project on GitHub and decided to provide examples via JSFiddler. I could easily take latest files and host it on the same host as this blog but that would make a headache for me as I would have to update files on my host as soon as I update file in GitHub.

So I googled a little bit and found a solution. People from GitHub were thinking about this so they provided a raw link for the files and it is pretty easy to use it. I'll show it on example for my JQuery plugin I'm working on currently.

First navigate to a file though GitHub website. For my project this will be as following:

If you reference this in your fiddle it won't work, because this url returns a page. What you have to do is to change URL a bit to get a raw file as a response.

  1. instead of put
  2. remove blob from the URL address

After these changes URL will be:

This is fine to use it for you fiddles, but I do not recommend to use this as a CDN because simply GitHub is not a CDN. Time of response is not that short, so using it as a CDN is not a good idea, bot for using in fiddles makes it really useful.

  • Share


Purpose of the code contained in snippets or available for download in this article is solely for learning and demo purposes. Author will not be held responsible for any failure or damages caused due to any other usage.

Comments for this article

comments powered by Disqus