Disable cache for some images

前端 未结 13 1127

I generate some images using a PHP lib.

Sometimes the browser does not load the new generated file.

How can I disable cache just for images created dynamica

13条回答
  •  既然无缘
    2020-11-22 08:28

    A common and simple solution to this problem that feels like a hack but is fairly portable is to add a randomly generated query string to each request for the dynamic image.

    So, for example -

    
    

    Would become

    
    

    Or

    
    

    From the point of view of the web-server the same file is accessed, but from the point of view of the browser no caching can be performed.

    The random number generation can happen either on the server when serving the page (just make sure the page itself isn't cached...), or on the client (using JavaScript).

    You will need to verify whether your web-server can cope with this trick.

提交回复
热议问题