Webmasters Stack Exchange is a question and answer site for pro webmasters. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 2 down vote accepted

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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