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

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

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

这似乎适用于 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 浏览器缓存图像

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

发布评论

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

>www.elefans.com

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