Search code examples
ruby-on-railscachingpassengeriiif

From the server, how do I force an external file to expire so that the browser receives a fresh one?


I have a show view, that uses a 'Universal Viewer' to load images. The image dimensions come from a json file that comes from a IIIF image server.

I fixed a bug and a new json file exists, but the user's browser is still using the old info.json file.

I understand that I could just have them do a hard-reload, like I myself did on my machine, but many users may be affected, and I'm just damn curious now.


Solution

  • It depends on where the JSON file is being served from, and how it's being cached.

    The guaranteed way to expire the cache on the file is to change the filename every time it changes. This is typically done be renaming it filename-MD5HASH.ext, where the MD5HASH is the MD5 hash of the file.

    If you can't change the file name (it comes from a source you can't control, you might be able to get away with adding a caching busting query key to the URL. Something like http://example.com/file.ext?q=123456.