如何强制Web浏览器缓存图片 [英] How to force a web browser to cache Images

查看:587
本文介绍了如何强制Web浏览器缓存图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am writing a small application which serves images from the local computer, so they can be accessed as http://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浏览器缓存图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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