gpt4 book ai didi

java - 有什么方法可以阻止浏览器每秒请求相同的图像?

转载 作者:行者123 更新时间:2023-12-02 00:05:05 25 4
gpt4 key购买 nike

我的 jsp 页面每秒刷新一次。页面上有两张图片。一个重 13 KB,另一个重 4 KB。 Firefox 不会一次又一次地加载图像,但 Chrome 会一次又一次地加载这两个图像。而且看起来很糟糕!有什么方法可以阻止浏览器一次又一次请求相同的图像?

最佳答案

您应该设置适当的Expire header 和Last-Modified header 。来自 the maker of Chrome :

Recommendations

  • Set caching headers aggressively for all static resources. For all cacheable resources, we recommend the following settings: Set Expires to a minimum of one month, and preferably up to one year, in the future. (We prefer Expires over Cache-Control: max-age because it is is more widely supported.) Do not set it to more than one year in the future, as that violates the RFC guidelines. If you know exactly when a resource is going to change, setting a shorter expiration is okay. But if you think it "might change soon" but don't know when, you should set a long expiration and use URL fingerprinting (described below). Setting caching aggressively does not "pollute" browser caches: as far as we know, all browsers clear their caches according to a Least Recently Used algorithm; we are not aware of any browsers that wait until resources expire before purging them.

  • Set the Last-Modified date to the last time the resource was changed. If the Last-Modified date is sufficiently far enough in the past, chances are the browser won't refetch it.

如果您在 HTTPS 下提供服务,则需要在服务器上拥有正确签名的证书,否则 Chrome 不会缓存任何内容。

关于java - 有什么方法可以阻止浏览器每秒请求相同的图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14051338/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com