33

I've got a repository on github with a .css file in it. Is there any way to have github serve this file in a way that I can consume it in a web page?

In other words, I'd like to be able to reference this source file at github directly, from an HTML file on my local computer or a live domain. Something like:

<link rel="stylesheet"
      type="text/css"
      href="http://github.com/foouser/barproject/master/xenu-is-my-lover.css"
/>

I've tried including a<link> to the "raw" source file (http://raw.github.com...), but github serves its Content-Type as text/plain, and consequently, Chrome and FF are not adding its content as CSS styles to the page—the file's data is being discarded and a warning is shown in the debugger consoles of the browsers.

user979672
  • 1,723
  • 3
  • 22
  • 31
  • 1
    possible duplicate of [Link and execute external JavaScript file hosted on GitHub](http://stackoverflow.com/questions/17341122/link-and-execute-external-javascript-file-hosted-on-github) – Troy Alford Oct 24 '14 at 20:43
  • (try this) You can create a `folder/file.css` and serve it from GitHub pages. Just follow the correct path from the URL and get the file when referencing it from your local html file. – carloswm85 Nov 27 '21 at 18:00

5 Answers5

65

Important: rawgit.com is shutting down. Read more about other alternatives here - https://rawgit.com/


Found something really cool. You get the raw link as: http://raw.github.com/...

Simply fetch the files from rawgit.com (or cdn.rawgit.com) instead of raw.github.com and DONE!


UPDATE:

You can also use raw.githack.com if you want to serves raw files directly from Bitbucket or GitLab

Kushagra Gour
  • 4,320
  • 2
  • 19
  • 22
19

GitHub repos aren't web hosting, you should push that stuff up to a service specifically designed to serve files, like pages.github.com.

Tekkub
  • 29,227
  • 2
  • 28
  • 20
  • 1
    I don't think this is true. You can host static files on github, granted web hosting is better but it can work on github pages. – 32423hjh32423 Aug 02 '18 at 13:58
9

Check out https://gitcdn.link/ . Seems to work well.

Rawgit.com has shut down.

Squirrl
  • 4,500
  • 9
  • 44
  • 79
2
  • First Visit RawGit as suggested earlier
  • Next copy your file path from github into the RawGit box
  • RawGit will automatically produce two refrences to your web page
  • The Development and Production refrence
  • refrence the development link in your webpage if you are still developing
  • save/upload then reload your webpage
  • if there was no change it means your browser has saved your former refrence
  • clear your browser data then reload
  • Hope that helps?
Toye_Brainz
  • 100
  • 7
1

You have to use RawGit which, is a part of MaxCDN, serve files directly from the GitHub repository with the correct content type header. Full tutorial, click here

Vishal Chopra
  • 364
  • 5
  • 9