21

How can I load a JavaScript file from raw.github.com? This code for CSS works perfectly well:

<link rel="stylesheet" type="text/css" href="https://raw.github.com/myusername/myrepo/master/style.css">

But it will not work for JavaScript:

<script src="https://raw.github.com/myusername/myrepo/master/script.js"></script>
Ptr13
  • 553
  • 2
  • 6
  • 14

1 Answers1

29

You cannot load JavaScript from Github because the content type is not application/javascript or text/javascript.

This is done intentionally to prevent you from using Github as a CDN, which is in violation of their terms of service.

See also: https://rawgithub.com/

And this: https://github.com/blog/1482-heads-up-nosniff-header-support-coming-to-chrome-and-firefox

Brad
  • 159,648
  • 54
  • 349
  • 530
  • 1
    Huh. Well. Can I just delete that question? – Ptr13 Oct 10 '13 at 01:44
  • 7
    @Ptr13, What for? Why not just accept the answer so that others can find it in the future? StackOverflow is for learning from everyone's questions/answers, not just for getting your own personal question answered. – Brad Oct 10 '13 at 01:44
  • @Brad: I don't think using GitHub as a CDN is against their ToS. It's just that the directory structure isn't guaranteed to be static for a repository, so your site can break unexpectedly. – Blender Oct 10 '13 at 01:47
  • @Blender I've seen it in their ToS before... let me see if I can dig it up. – Brad Oct 10 '13 at 02:16
  • *Abuse or excessively frequent requests to GitHub via the API may result in the temporary or permanent suspension of your account's access to the API. GitHub, in its sole discretion, will determine abuse or excessive usage of the API. GitHub will make a reasonable attempt via email to warn the account owner prior to suspension. If your bandwidth usage significantly exceeds the average bandwidth usage (as determined solely by GitHub) of other GitHub customers, we reserve the right to immediately disable your account or throttle your file hosting until you can reduce your bandwidth consumption.* – Brad Oct 10 '13 at 02:20
  • I guess that's not quite use-raw-as-hosting-and-you're-in-violation as much as it is don't-do-things-that-aren't-nice-or-we'll-be-unhappy, but the principal applies. – Brad Oct 10 '13 at 02:21
  • See this as well: https://github.com/blog/1482-heads-up-nosniff-header-support-coming-to-chrome-and-firefox – Brad Oct 10 '13 at 02:22
  • 1
    @Brad: You're right. I guess I'm not too good at skimming legal documents. – Blender Oct 10 '13 at 02:37