禁用某些图像的缓存 [英] Disable cache for some images

查看:84
本文介绍了禁用某些图像的缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用PHP库生成一些图像。



有时浏览器不加载新生成的文件。



如何禁用缓存仅用于由我动态创建的图像?



注意:我必须使用相同的名称为创建的图像随着时间的推移。

解决方案

这个问题的常见和简单的解决方案,感觉像一个黑客,但相当便携是为动态图像的每个请求添加一个随机生成的查询字符串。



因此,例如 -

 < img src =image.png/> 

会变成

 < img src =image.png?dummy = 8484744/> 



 < img src =image.png?dummy = 371662/> 

从Web服务器的角度来看,访问同一个文件,但是从浏览器的视图不能执行缓存。



随机数字的生成可以在服务器发生时发生(只要确保页面本身没有被缓存...)或客户端(使用JavaScript)。



您需要验证您的Web服务器是否可以应付这个伎俩。 b $ b

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 dynamically by me?

Note: I have to use same name for the created images over time.

解决方案

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 -

<img src="image.png" />

Would become

<img src="image.png?dummy=8484744" />

Or

<img src="image.png?dummy=371662" />

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.

这篇关于禁用某些图像的缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆