Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

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
add comment

1 Answer 1

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
add comment

Your Answer

 
discard

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.