Reputation: 26259
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
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:
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"?
Upvotes: 69
Views: 11593
Reputation: 21739
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.
Upvotes: 28
Reputation: 14873
I had a look at what shields.io does.
It sets this header (Source):
Cache-Control: max-age=2592000
Upvotes: 8
Reputation: 10010
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.
Upvotes: 5