canonical-web-and-design / build.snapcraft.io

The Snapcraft Build site.
GNU Affero General Public License v3.0
21 stars 26 forks source link

Furthur Reduce Caching on Build Badge #1248

Closed zicklag closed 4 years ago

zicklag commented 4 years ago

Summary

Sometimes GitHub still caches the Build badge with an out-of-date image. This was addressed by #1101, but I still get out-of-date images on my README sometimes.

Process

It doesn't seem to happen all of the time and sometimes it will fix it if I use Ctrl+R to refresh and clear the browser cache, but when I push my code to master and then view my README, the page will display a stale build status.

Current and expected result

I would expect that the build badge should always reflect the current build status.

Screenshot

N/A

Proposed Fix

I have another build badge on my README for the Drone CI service and it is always up-to-date. Comparing the headers from the two badges shows a difference in the Cache-Control header:

Drone:

Cache-Control : no-cache, no-store, max-age=0, must-revalidate, value

Snapcraft:

Cache-Control : no-cache

I propose that we update the Snapcraft build badge header to match that of Drone's.

Another note is that the Drone badge response also contained a couple extra headers to really make sure that the response is not cached:

Expires : Thu, 01 Jan 1970 00:00:00 GMT
Pragma : no-cache

Pragma is really just for backward compatibility with the old HTTP/1.0 spec, and setting the expire time to 1970 might be a little overkill, but it is very nice that the badge is absolutely never cached by anything.

Arguably the extra no-store, max-age=0, must-revalidate, value flags in the Cache-Control header may be enough to fix any issue, but we might want to add the other headers just to make sure.

Also for extra reference, a comment ( https://github.com/github/markup/issues/224#issuecomment-48532178 ) in a GitHub support issue suggested:

We're pretty confident that the image caching works. If you're having issues with something like a CI badge, make sure the image has the Cache-Control: no-cache header, and either Expires, Last-Modified or Etag. See the Fastly documentation for more info.

Snapcraft does have an Etag header set, but my experience seems to indicate that we still need more cache prevention measures.

zicklag commented 4 years ago

Created #1249 with my proposed changes.