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

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

问题描述

我正在编写一个小应用程序,它提供来自本地计算机的图像,因此它们可以作为 http://访问localhost:12345/something/something(返回一个 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

这似乎适用于 Firefox 3.x,但对于其他浏览器是否也适用于全局?

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

推荐答案

A Last-Modified过期 标题也可能是有用的补充.

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

您的服务器还应检查具有 If-Modified 的请求-Since 标头,并在可能的情况下返回 304 Not Modified 响应以加快速度.

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天全站免登陆