【问题标题】:How to avoid a browser request using Expires如何使用 Expires 避免浏览器请求
【发布时间】:2013-11-21 09:09:16
【问题描述】:

我正在编写一个 Java 网络服务,用于网络优化方面的培训。我的网络服务发送的响应将在 365 天后过期

@Path("cache2")
public class WsCache {
    @GET
        @Produces("application/json")
    public Response expires(){
        System.out.println("Expires in 365 days");
        String later = getDaysAfterHttpDate(365);
        return Response.ok("{Hello:hello}").header("Expires",later).build();
    }
}

问题是 Chrome 或 Firefox 使用缓存控制发出请求:

GET /fora-comments-ejb/api/cache2 HTTP/1.1
Host: localhost:8080
Connection: keep-alive
Cache-Control: max-age=0
Accept: text/html...
User-Agent: Mozilla/5.0 ...
Accept-Encoding: gzip,deflate,sdch
Accept-Language: fr-FR,fr;...

因为max-age 的任何值都会覆盖Expires,有没有办法说Firefox/Chrome 不对第二个请求使用缓存控制?

【问题讨论】:

    标签: http-headers cache-control


    【解决方案1】:

    通常,稍后我发现answer on Stack. 你需要一个真实 链接来缓存,或者浏览器发送一个max-cache=0,在我看来,这是一个很好的想法。

    我只需要制作一个带有链接的 html 文件:

    <a href="fora-comments-ejb/api/cache">Fetch some JSON<a/>
    

    它可以工作

    【讨论】:

      猜你喜欢
      • 2017-12-08
      • 2019-08-28
      • 1970-01-01
      • 1970-01-01
      • 2011-12-29
      • 2015-02-19
      • 1970-01-01
      • 2014-08-12
      • 1970-01-01
      相关资源
      最近更新 更多