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
@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