61

In one of my project I'm using an external image link to display a screenshot via the GitHub page, which automatically parses the README.rst

GitHub page of ROyWeb

I updated this screenshot on my web server several times in the last weeks and I just realised that it is not updated on the GitHub page since... well I think it never updated ;-) GitHub somehow downloaded the image and loads it from it's cache servers.

Within the README.rst, there is clearly the correct link:

Actual link to the ROyWeb screenshot

Which you can confirm, when you load the raw file:

raw README.txt on GitHub

But when I check the URL of the displayed image on the GitHub page, I get:

GitHub cached screenshot of ROyWeb

Does anyone know how to force a "recache"?

2
  • I would also be interested to know the answer to this.
    – b85411
    Jan 9, 2015 at 6:41
  • 2
    Then vote up the question @b85411 ; )
    – tamasgal
    Jan 9, 2015 at 8:51

4 Answers 4

86
curl -X PURGE {url of cached badge image}
11
  • 5
    This doesn't work for me. Is there another approach? My readme is a mess of missing images (mostly shields.io badges). Is this a known bug with any prospect of a fix?
    – orome
    Jan 19, 2017 at 15:25
  • 1
    Thats amazing! Out of curiosity, where did you find this information. I dont think PURGE is a standard http method? May 11, 2018 at 9:08
  • 5
    @MichaelAquilina I don't know how he finds it but Github mentions it here.
    – 张实唯
    Aug 27, 2018 at 5:17
  • 5
    This does work indeed! If it doesn't for you, press the Ctrl key while clicking refresh, you're probably getting the image from your own cache (I had to do this).
    – BenMorel
    Apr 25, 2019 at 9:43
  • 1
    Make sure to refresh with Ctrl-Shift-R to clear your browser cache.
    – makeworld
    Oct 24, 2020 at 16:23
21

There is also a trick that can be useful. It is nothing but just adding a question mark at the end of the image extension.

![This is an automated blog post image using Azure Function](https://customurl.blob.core.windows.net/github/latestpost.png?)

See the question mark (?) at the end. You can also see the live example here in my GitHub profile.

You can see more about this here.

4
  • 2
    You are amazing! Apr 15, 2021 at 9:21
  • 1
    Based @Sibeesh Venu
    – NoahVerner
    Feb 26, 2022 at 14:21
  • 1
    This should be the best answer!
    – Míng
    Aug 25, 2022 at 3:16
  • This seems to work for the first request, but if you update the image it does not update on subsequent requests for me.
    – Tim Ramsey
    Aug 16 at 20:32
7

I had a look at what shields.io does.

It sets this header (Source):

Cache-Control: max-age=2592000
1
  • 2
    I had seen that idea here but had no idea what syntax to use with a raw URL. Following your second link showed me how to do it. Thanks.
    – Mars
    Aug 1, 2017 at 4:13
2

I believe I've understood how to do this now. Instead of serving a raw png file for example, serve the image through a php file (many examples on SO).

Once you're displaying the image with PHP, add the following headers:

header('Cache-Control: no-cache');
header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', time() - 36000));

By setting the no-cache and having the cache expire in the past, I have found that GitHub's CDN updates the images automatically on every refresh.

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.