PNG 图像输出的标头以确保其在浏览器中缓存?
我有动态生成的图像(PNG),并将嵌入网站和论坛中。当图像发布在非常繁忙的页面上时,就会有很多连接来为不经常更改的内容提供服务。我想告诉浏览器缓存它多长时间。
那么我需要什么标题?目前,我有:
Cache-Control: max-age=86400
Content-Type: image/png
浏览器似乎没有缓存图像(大约20-30kb)。还需要什么?
编辑: 这是一个示例图像,我已经有一个带有 .png
扩展名的 URL: https://images.carspending.com /sigimg/5734/user/honda-accord-2-4i-executive-tourer_medium.png
I have images (PNG) that are generated dynamically and will be embedded in websites and forums. When an image gets posted on a very busy page, there are a lot many connections to service for something that doesn't change often. I want to tell the browser for how long to cache it.
So what headers do I need? Currently, I have:
Cache-Control: max-age=86400
Content-Type: image/png
It seems that the browser is not caching the image (it is about 20-30kb). What else would be necessary?
Edit:
This is an example image, I already have an URL with .png
extension:
https://images.carspending.com/sigimg/5734/user/honda-accord-2-4i-executive-tourer_medium.png
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
最后一件事是:
现在,浏览器在加载嵌入图像的页面时不会发出图像请求。
The final thing that worked was:
Now the browser does not make requests for the image when loading a page with embeded one.
确保您还添加了 public,如下所示:
另请阅读此内容,非常有帮助。
Make sure you also add public as so:
Read this also, is very helpful.
Expires
标头应该会有所帮助。An
Expires
header should help.