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

10.4k views Asked by At

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

4

There are 4 answers

11
Alex Skrypnyk On BEST ANSWER
curl -X PURGE {url of cached badge image}
6
Sibeesh Venu On

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.

1
b85411 On

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.

1
User On

I had a look at what shields.io does.

It sets this header (Source):

Cache-Control: max-age=2592000