Suppose I serve an image and if someone visits from a forum then I want it to download that image. If they visit again from the same forum then I want it to use cache, but if they visit from another forum and reference that same image I want it go ahead and re download that image. Is that possible?


The proper way to do this is to use the HTTP Vary header, like this:

Vary: Referer

Note that you can't actually tell the browser to automatically use the cached copy for all requests from the "same forum", for two reasons: first, the browser has no idea what constitutes a "forum", and second, even if you defined "same forum" as, say, "same domain", the Vary header cannot express that. All you can say is "re-check with the server for each referrer", which in practice means "for each page on which the image is used". Thus, you should make sure that your server supports efficient file revalidation, e.g. via ETagheaders.

  • Should also note that browser's don't really seem to care about Vary: Referer but web caches do. – Aeyoun Aug 2 '16 at 4:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.