Refresh image with a new one at the same url

后端 未结 19 3347
南旧
南旧 2020-11-21 22:00

I am accessing a link on my site that will provide a new image each time it is accessed.

The issue I am running into is that if I try to load the image in the backgr

19条回答
  •  闹比i
    闹比i (楼主)
    2020-11-21 22:42

    One answer is to hackishly add some get query parameter like has been suggested.

    A better answer is to emit a couple of extra options in your HTTP header.

    Pragma: no-cache
    Expires: Fri, 30 Oct 1998 14:19:41 GMT
    Cache-Control: no-cache, must-revalidate
    

    By providing a date in the past, it won't be cached by the browser. Cache-Control was added in HTTP/1.1 and the must-revalidate tag indicates that proxies should never serve up an old image even under extenuating circumstances, and the Pragma: no-cache isn't really necessary for current modern browsers/caches but may help with some crufty broken old implementations.

提交回复
热议问题