Mobile app version of vmapp.org
Login or Join
Hamaas447

: Is it possible to invalidate cache when the referrer adress is different? Suppose I serve an image and if someone visits from a forum then I want it to download that image. If they visit

@Hamaas447

Posted in: #CacheControl #Http

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?

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Hamaas447

1 Comments

Sorted by latest first Latest Oldest Best

 

@Rambettina238

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.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme