How to prevent Github from caching images in markdown files

I’m trying to add an image to a markdown file in my repo. The server updates the image every minute, but the image is cached by Github and therefore does not update in the readme.

I’m sending a cache-control header from a .htaccess file which looks like this:

set Cache-control: private, max-age=0, no-cache

I have limited understanding of caching, but I’ve noticed that Github Pages doesn’t cache the image when building the site, but it still caches the image in the readme. 

Original picture (updated once per minute)

Checking the Network tab on Chrome shows that the original image is sending this request header:

Cache-Control: no-cache

Cached by Github
But Github’s cached image is sending this request header:

Cache-Control: public, max-age=31536000

Hi @paramt 

When I fetch your source image, I get no Cache-Control headers.

$ curl -sv -o /dev/null
* Trying
* Connected to ( port 80 (#0)
> GET /chart.png HTTP/1.1
> Host:
> User-Agent: curl/7.54.0
> Accept: */*
< HTTP/1.1 200 OK
< Date: Wed, 27 Mar 2019 16:37:41 GMT
< Server: Apache/2.4.29 (Ubuntu)
< Last-Modified: Wed, 27 Mar 2019 16:37:05 GMT
< ETag: "6c4c-585160c4ebb97"
< Accept-Ranges: bytes
< Content-Length: 27724
< Content-Type: image/png
{ [2564 bytes data]
* Connection #0 to host left intact

I finally figured it out and it wasn’t a problem with Github, but rather with my response headers (as @seveas pointed out). My .htaccess file wasn’t being recognized.

1 Like