40

I have a gist with some javascript code in a script tag, like so:

<script src="https://raw.github.com/gist/b25dff23c2c4b4bd425a/f157aa95163311c4b58febb06b49ffd16419f642/images.js"></script>

And I will need to keep editing the JS file on github. However, when you edit a gist it changes the URL of the gist. How do I keep the same URL?

tckmn
  • 57,719
  • 27
  • 114
  • 156
  • 1
    I don't think you can, it creates a new url everytime. If you have a repo you can just put a test folder there an load it from the repo. – elclanrs Sep 20 '12 at 23:54

6 Answers6

57

Gist changed the path to this file pattern:

https://gist.github.com/<USER_NAME>/<GIST_ID>/raw/<GIST_REVISION_ID>/<GIST_FILE_NAME>

You will notice that now the top answers' links are 404'ing.

Simply apply this new pattern and voilà!

https://gist.github.com/<USER_NAME>/<GIST_ID>/raw/<GIST_FILE_NAME>

For instance:

https://gist.githubusercontent.com/wesbos/cd16b8b1815825f111a2/raw/lol.js

cregox
  • 17,674
  • 15
  • 85
  • 116
marclundgren
  • 686
  • 6
  • 3
  • 2
    Don't be put off by the fact that the example link here results in a 404; that's because marclundgren has moved/removed/renamed his gist, not because the pattern doesn't work. – Tim Apr 24 '16 at 04:28
  • 2
    At first I thought that this answer wasn't working. After a little bit of waiting/experimentation, it seems that Github has some internal caching happening on this kind of Gist URL. It took 2-3 minutes for the changes to reflect in my browser, even when forcing a no-cache refresh. – taylorthurlow Jul 01 '20 at 18:16
18

In case of gist,
https://raw.github.com/gist/[gist_id] OR
https://gist.github.com/[user_name]/[gist_id]/raw(which is more likely to be an unique URI.)
returns first file from the gist.

For gist with multiple files, https://raw.github.com/gist/[gist_id]/[file_name]

The url works even when you change the filename.

e.g. https://raw.github.com/gist/4636655 https://raw.github.com/gist/4636655/imdb-getglue.js

Bohr
  • 1,566
  • 1
  • 16
  • 21
xtranophilist
  • 582
  • 8
  • 14
  • The `https://raw.github.com/gist/[gist_id]` part doesn't seem to work anymore, at least if `gist_id` is the full SHA of the gist - it gives `400: invalid request`. – BeeOnRope Nov 25 '18 at 19:09
12

Just add /raw to the end of your gist url.

https://gist.github.com/--user--/--id--/raw

This links to the latest revision of that file.

After updating the gist file, changes are reflected after a minute or two.

spencer.sm
  • 19,173
  • 10
  • 77
  • 88
3

You can't change the content without submitting it (saving it) and that gives you a new URL.

If you want a link to something you will be constantly changing and have the URL always be the same, put it in a repo and save changes by committing it.

You'll end up with something like:

https://raw.github.com/UserName/Repository/master/script.js

BSull
  • 329
  • 2
  • 10
  • okay, so how does this repo thing work? I have https://github.com/OddLlama/images so how do I use it? – tckmn Sep 21 '12 at 00:00
  • You clone it to your machine. Use either the app for mac or windows if you don't want to do it by command line. – BSull Sep 21 '12 at 00:01
3

The other methods didn't work, so I'm using rawgit.com:

https://rawgit.com/<user>/<id>/raw/<file>
jpillora
  • 5,194
  • 2
  • 44
  • 56
1

It is also possible to remove your username from the url, if you want.

Take the url from the accepted answer above:

https://gist.github.com/<USER_NAME>/<GIST_ID>/raw/<GIST_FILE_NAME>

remove <USER_NAME> and move raw in front of <GIST_ID>, where the username was:

https://gist.github.com/raw/<GIST_ID>/<GIST_FILE_NAME>

But it doesn't work with RawGit.

user1852180
  • 62
  • 2
  • 6