How to force image (cache) update in README.rst on GitHub

GithubReadme

Github Problem Overview


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"?

Github Solutions


Solution 1 - Github

curl -X PURGE {url of cached badge image}

Solution 2 - Github

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.

Solution 3 - Github

I had a look at what shields.io does.

It sets this header (Source):

Cache-Control: max-age=2592000

Solution 4 - Github

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestiontamasgalView Question on Stackoverflow
Solution 1 - GithubAlex SkrypnykView Answer on Stackoverflow
Solution 2 - GithubSibeesh VenuView Answer on Stackoverflow
Solution 3 - GithubUserView Answer on Stackoverflow
Solution 4 - Githubb85411View Answer on Stackoverflow