如何强制Web浏览器缓存图片

编程入门 行业动态 更新时间:2024-10-24 12:28:40
本文介绍了如何强制Web浏览器缓存图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我写一个小的应用程序,它从本地计算机图像服务,使他们能够为 HTTP访问://本地主机:12345 /东西/ 的东西(它返回一个JPEG)。

I am writing a small application which serves images from the local computer, so they can be accessed as localhost:12345/something/something (which returns a jpeg).

如何可以强制浏览器缓存此,因此只有一个单一的请求将被发送到服务器。将这个头就足够了。

How can I force the browser to cache this, so only a single request would be sent to the server. Would this header be sufficient

HTTP/1.1 200 OK Cache-Control: public, max-age=99936000 Content-Length: 123456 Content-Type: image/jpeg

这似乎与3.X Firefox的工作,但它足以为全球浏览器等也?

This seems to work with Firefox 3.x but would it be sufficient globally for other browser as well?

推荐答案

一个修改和过期头也可能是有益的补充。

A Last-Modified and Expires header might also be useful additions.

您的服务器还应该检查设有一个如果-Modified-Since的头,并返回一个304未修改响应,如果可能的飞驰的东西。

Your server should also check for requests featuring an If-Modified-Since header, and return a 304 Not Modified response if possible to speed things along.

更多推荐

如何强制Web浏览器缓存图片

本文发布于:2023-10-31 19:08:11,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1547005.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:缓存   浏览器   图片   Web

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!