How to force image (cache) update in README.rst on 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.
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.
I had a look at what shields.io does.
It sets this header (Source):
Cache-Control: max-age=2592000
curl -X PURGE {url of cached badge image}