Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reference GitHub file in jsFiddle

Is there a possibility to misuse grab files from a github repo as external resources in jsFiddle?

like image 704
kaiser Avatar asked Mar 23 '12 14:03

kaiser


3 Answers

TLDR; Visit rawgit.com which will pop your files on a CDN straight from GitHub so you can use them.

Unfortunately none of the answers here worked for me. The rawgithub URL didn't seem to work as the connection gets refused. So here's a full solution that did work. Firstly in GitHub you need to click the Raw button to get the original JavaScript.

enter image description here

Then copy the URL from the page it takes you too. You'll notice if you try and use this directly you'll get a warning from JSFiddle.

enter image description here

More to the point is the browser will give you an error, e.g.:

Refused to execute script from https://raw.githubusercontent.com/nnnick/Chart.js/master/Chart.min.js' because its MIME type ('text/plain') is not executable, and strict MIME type checking is enabled.

Take that URL and visit rawgit.com. This will give you a URL of the format https://rawgit.com/nnnick/Chart.js/master/Chart.min.js which you can then use.

I've tried and tested this and it seems to work fine without issue

like image 135
Ian Avatar answered Nov 09 '22 18:11

Ian


This is an updated answer, since the url's have changed slightly for Github... I ran into this issue and figured it out for present day. Hopefully this helps people out finding this post recently. Example for Bootstrap Slate theme from Bootswatch:

  1. Raw file url: https://raw2.github.com/thomaspark/bootswatch/gh-pages/slate/bootstrap.css

  2. Remove the 2. after raw: https://rawgithub.com/thomaspark/bootswatch/gh-pages/slate/bootstrap.css

That's it! :D

like image 25
Megaroeny Avatar answered Nov 09 '22 19:11

Megaroeny


Nowadays JSDelivr seems to be the best option.

like image 5
peterhil Avatar answered Nov 09 '22 20:11

peterhil