[Mediawiki-l] Image caching on File: pages... any workaround?

Brion Vibber brion at pobox.com
Tue Sep 6 17:45:42 UTC 2011

On Tue, Sep 6, 2011 at 7:05 AM, Daniel Barrett <danb at vistaprint.com> wrote:

> The most frequent problem on our wiki (MediaWiki 1.17.0) involves
> re-uploads of images, where users are fooled by browser caching:
> 1.      A user uploads a modified version of an existing image
> (File:Foobar.jpg)
> 2.      After the upload, user views File:Foobar.jpg but the old image is
> still showing.
> 3.      User tries uploading 10 more times. The old image is still showing.
> 4.      User calls tech support, who says, "press ctrl-F5 to refresh your
> browser."
> 5.      User presses ctrl-F5 and the new image shows up.
> Obviously the problem is due to browser caching. Is there any way for the
> MediaWiki software to prevent this problem from happening and show only
> uncached images on File:Foobar.jpg? The average user doesn't know anything
> about browser caching.

Couple things to try:

1) Change your web server configuration to send a Cache-Control header
telling browsers to double-check all files in your image uploads directory,

  Cache-Control: public, must-validate

This may make images load slightly more slowly, but should still make use of
the cache -- images should be re-checked on every page load but only
actually re-downloaded when they change.

2) Try to figure out what bit of code makes the actual view URLs (including
thumbnails) and append a timestamp in a query string to make it a distinct
URL for each upload version. Not sure how convenient this is... possible
MediaTransformOutput::toHtml(), or perhaps in whatever sticks a URL into the
MediaTransformOutput object? Meh. :)

Note there have been vague plans on the table for some years to restructure
image storage in a way that gives a unique URL for each version of a file
(bypassing this problem and also merging storage of duplicate files) but we
only ever got it implemented for deleted files.

-- brion

More information about the MediaWiki-l mailing list