Skip to content
Advertisement

How can I use github to host an external CSS file?

I uploaded my css to github, then went to the file on the site and clicked the raw option. I tried adding it to a webpage, but chrome is giving me the following errors:

Resource interpreted as Stylesheet but transferred with MIME type text/plain: “https://raw.githubusercontent.com/me/my-repo/master/style.css”.

and

Cross-Origin Read Blocking (CORB) blocked cross-origin response https://raw.githubusercontent.com/me/my-repo/master/style.css with MIME type text/plain. See https://www.chromestatus.com/feature/5629709824032768 for more details.

What can I do to add this CSS successfully? I’m adding it with javascript too:

var link = document.createElement('link');
link.setAttribute('rel', 'stylesheet');
link.setAttribute('type', 'text/css');
link.setAttribute('href', 'https://raw.githubusercontent.com/me/my-repo/master/style.css');
document.getElementsByTagName('head')[0].appendChild(link);

Advertisement

Answer

You can host your files on Github Pages, Just go to repo settings[1], find “Github Pages” section and set your branch[2] and click “Save”. You will se the info[3]. Then you go to https://YOUR-GITHUB-USERNAME/REPO-NAME (If you have index.html or any file eg. /src/css/style.css) You can load the CSS, JS or other files on any site

<link rel="stylesheet" href="path/to/file/style.min.css">

[1]:

Settings


[2]:

Branch


[3]:

Success Info

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement