使对PNG图像输出接头确保它能够在浏览器缓存? [英] Headers for PNG image output to make sure it gets cached at browser?

查看:163
本文介绍了使对PNG图像输出接头确保它能够在浏览器缓存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了动态图像(PNG),会有太多连接到我的论坛的东西,不经常更改。我已经缓存生成的图像,我希望减少连接。

I have created dynamic images (PNG) that are generated with PHP script and will be used to show data from my service for example on forum boards, etc. If the image gets posted on very busy forums, there will be too many connections to my forums for something that doesn't change often. I already cache the generated image, I want to reduce the connections.

那么,我需要什么样的头?目前,我已经用了:

So what headers do I need? Currently I have went with:

header('Cache-Control: max-age=86400');
header('Content-Type: image/png');

看来这个浏览器不缓存图像(它是关于20-30kb)。火狐6,至少是没有的。还有什么将需要使缓存客户端。

It seems that the browser is not caching the image (it is about 20-30kb). Firefox 6 at least isn't. What else would be needed to make it cached client side.

编辑:
这是一个例子形象,我已经是谎言于具有产生它的脚本结束的.png浏览器:
<一href=\"http://images.carspending.com/sigimg/1/user/honda-accord-i-ctdi-executive_big.png\">http://images.carspending.com/sigimg/1/user/honda-accord-i-ctdi-executive_big.png

推荐答案

这是工作的最后一件事是:

The final thing that worked was:

header('Pragma: public');
header('Cache-Control: max-age=86400');
header('Expires: '. gmdate('D, d M Y H:i:s \G\M\T', time() + 86400));
header('Content-Type: image/png');

现在加载带嵌入式一个页面时,浏览器不会使图像的请求。

Now the browser does not make requests for the image when loading a page with embeded one.

这篇关于使对PNG图像输出接头确保它能够在浏览器缓存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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