Skip to content

Instantly share code, notes, and snippets.

@atenni
Last active October 31, 2024 06:12
Show Gist options
  • Save atenni/5604615 to your computer and use it in GitHub Desktop.
Save atenni/5604615 to your computer and use it in GitHub Desktop.
How to permalink to a gist's raw file
@yairEO
Copy link

yairEO commented Aug 8, 2020

@MichaelCurrin - everyone else already wrote the same here, years before your "solution" epiphany

@MichaelCurrin
Copy link

Yes as I posted without reading all the comments.

I also added to embed section of the docsify site so this approach be found there easier

https://docsify.js.org/#/embed-files?id=embed-a-gist

https://github.com/docsifyjs/docsify/pull/1238/files

@maximousblk
Copy link

Best answers imo would be

https://gist.github.com/raw/[ID]/[REVISION]/[FILE]

or

https://gist.githubusercontent.com/raw/[ID]/[REVISION]/[FILE]

[ID] is necessary
[REVISION] can be omitted to get the latest revision
[FILE] can be omitted to get the first file

@jerrygreen
Copy link

I'm also wondering how did he get SO SHORT url (with short hash) in the first place:

https://gist.github.com/atenni/5604615

I'm suspecting back in 2013 Github allowed to use such shorter urls, and it's now impossible to make. But I wonder if I'm wrong

@barraIhsan
Copy link

I'm also wondering how did he get SO SHORT url (with short hash) in the first place:

https://gist.github.com/atenni/5604615

I'm suspecting back in 2013 Github allowed to use such shorter urls, and it's now impossible to make. But I wonder if I'm wrong

yeah maybe

@Kuju29
Copy link

Kuju29 commented Mar 3, 2021

This is URL worked for me. It will update after 4-5 min, I think so.

https://gist.githubusercontent.com/King1037/bd9861c08b86ac158d426ac91d14995d/raw/d956873ea1468sdfcca425c6cb2d0f7b63f8f4cdd/Ldsdfyer.fd.css

You just delete the text after Raw.
https://gist.githubusercontent.com/USERNAME/GIST_ID/raw
https://gist.githubusercontent.com/King1037/bd9861c08b86ac158d426ac91d14995d/raw

@0x49D1
Copy link

0x49D1 commented Mar 17, 2021

Thanks, that was nice: works for secret gists too.

@rjb3977
Copy link

rjb3977 commented Apr 3, 2021

You can use query parameters to get around caching if you want fast updates, i.e. every time you make a request append something like ?cache-bust=(some random url-safe string) to the URL. As far as I can tell, any query string works, so you can omit the cache-bust= if you want, or use donkey-poo= if you feel so inclined.

@revolter
Copy link

revolter commented Apr 3, 2021

@rjb3977, usually, an underscore and the current timestamp are used for this: ?_=1617443829.

@AlexAtkinson
Copy link

I found this discussion after looking into it myself. Here's what I've got:

  • GIST is NOT meant to behave like a repository. It is a Front End technology.
  • Without cache busting, updates take quite a while... Longer than I was going to wait to measure how long exactly.
  • WITH cache busting, you can reduce the latency of updates to ~30-60s, but there IS STILL LATENCY.

Here's what I used to observe and measure changes.
Note that I was adding a, b, c... to line 4 character 1 (after the pound/hash sign) every time I saw the change in the cli.

while true; do line=$(curl -s https://gist.githubusercontent.com/raw/2bf5c315a7895193ddc3fe647ef3976b/detect-ci.sh?cache-bypass=$(date +%s) | sed '4q;d'); echo "$(date) -- ${line:1:1}"; sleep 1; done

So, this should be good enough for MOST applications. Mileage may vary.
And there's always a risk that GH will change their caching behavior for these assets.

@kleinlennart
Copy link

Nice. Exactly what I needed, thank you! 🙏
I think this should be the default URL, or GitHub should at least be more explicit about this difference...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment