Page MenuHomePhabricator

Investigate / Fix upload.wikimedia.org lack of Cache-Control headers
Open, Needs TriagePublic

Description

While theorizing about T425216 , we noticed and wondered why we don't emit Cache-Control at all (towards end-clients) on upload.wm.o image fetches. We do emit ETag, Last-Modified, Date, and Age, and it's reasonable to assume (based on standards recommendations and general Internet discussions of the topic) that browsers will probably generally apply some kind of limited, heuristic caching based on those values, given no explicit C-C. Some sources expect something like 10% of the diff between Date and Last-Modified.

We should try to figure out a few things about this to better our own understanding of the linked bug and related things:

  • What behaviors do current majority browsers exhibit in this scenario wrt image caching?
  • Have those behaviors evolved in recent years?
  • What was "our" intent whenever whomever here last evaluated this situation, probably many years ago?
  • What do we want to do now? (probably, at least explicitly define a C-C header that unambiguously causes some intended behavior)

Event Timeline

Thanks for filing the task! I think we will need to investigate a bit more. For a data point to start with:

Image from the front page: https://upload.wikimedia.org/wikipedia/commons/4/41/2020_ICC_W_T20_WC_A_v_SL_02-24_Mooney_%2801%29_%28cropped%29.jpg. All the relevant headers set, except cache-control and that's expected because we are not actually setting it.

Firefox 152: Subsequent requests result in a 304. Cache disabled results in a 200 so that's also fine.

Chromium 149: Same behaviour.

We should verify that this behaviour is consistent but more importantly, perhaps we should look into setting an explicit cache-control header and decide on that.

We do emit ETag […]

See also T295556: Thumbor response lacks "ETag" HTTP header (fixed once expired from Varnish and re-filled from Swift) and T256217: Swift response sends invalid ETag header (missing double quotes), which together make it hard or impossible for clients to avoid re-downloading images when they revalidate them.

Investigate lack of Cache-Control headers

This is a duplicate of T19577: Thumbnail urls should be versioned and sent with Cache-Control max-age headers which was asking for Expires headers on thumbs URLs. That's alternative way of setting Cache-Control: max-age and normalizes to the same thing. I've updated it to recommend Cache-Control instead.

It's reasonable to assume (based on standards recommendations and general Internet discussions of the topic) that browsers will probably generally apply some kind of limited, heuristic caching based on those values, given no explicit C-C […]

Indeed. Given that we don't explicitly disallow caching, all browsers give themselves a minimal "max-age"-like allowance.

Setting anything explicitly is non-trivial because uploads in MediaWiki are primary content. Similar to articles this means:

  • users can edit it (reupload/overwrite files),
  • our CDN caches it (s-maxage equivalent),
  • MediaWiki purges the CDN,
  • browsers and other external clients are not allowed to blindly cache it (Cache-Control max-age=0),
  • users expect to see their own changes.

At T19577 it is proposed we version the URLs in some way, and then use our RefreshLinks (same as for templates, and global charts) to regenerate articles when the file revision changes.

We did resolve T38380 in the meanwhile which means you will see your own change on the File-description page regardles of browser cache. But this does not address use of images in articles. This works today with a hard refresh. If we set an explicit Cache-Control that would probably continue to work with a hard refresh. It would be nice if it "just" worked. But, that is a separate and potentially lower priority issue.

I guess the main question is whether there is a benefit to setting Cache-Control max-age.

See also: