【问题标题】:Cache-control header doesn't work for IE11缓存控制标头不适用于 IE11
【发布时间】:2020-10-03 14:13:35
【问题描述】:

谁能解释一下 IE11 的行为?

据我所知,所有支持 Http 1.1 的浏览器(除了一些有 bug 的版本)都支持 Cache-Control 标头。

我的后端只有Access-Control-Request-HeadersCache-ControlIf-Modified-Since,所以我不能使用ExpiresPragma。 就我而言,IE11 的行为很奇怪。

Cache-Control 的任何指令在 IE11 中根本不适合我。 IE11 只是缓存所有带有此类标头的请求:

  • Cache-Control: no-cache
  • Cache-Control: no-store, no-cache
  • Cache-Control: no-cache, max-age=0
  • Cache-Control: no-store, no-cache, max-age=0, must-revalidate
  • 以及任何其他指令组合。

有趣的是,只需添加 If-Modified-Since: 0 即可解决我的问题。

为什么 IE11(我在许多 PC 上尝试过)完全忽略 Cache-Control 而只是缓存所有数据?

请求的标头:

   Accept: */*
   Accept-Encoding: gzip, deflate
   Access-Control-Request-Headers: cache-control, expires, accept-language, x-website-token, authorization, x-website-config, accept
   Access-Control-Request-Method: GET
   Cache-Control: no-cache
   Content-Length: 0
   Host: ----
   Origin: ----
   User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko

响应的标题:

   access-control-allow-credentials: false
   access-control-allow-headers: DNT, User-Agent, X-Website-Token, X-Website-Config, X-Website-Dgp, X-Integration-Id, X-Requested-With, If-Modified-Since, Cache-Control, Content-Type,Range, Accept, Accept-Language, Authorization, DNT
   access-control-allow-methods: GET, POST, PUT, PATCH, DELETE, OPTIONS
   access-control-allow-origin: *
   access-control-expose-headers: X-Pagination-Total-Count, X-Pagination-Page-Count, X-Pagination-Current-Page, X-Pagination-Per-Page
   access-control-max-age: 3600
   content-type: application/json; charset=UTF-8
   date: Sat, 13 Jun 2020 23:01:32 GMT
   server: nginx/1.16.1
   set-cookie: x-last-referrer=;Domain=-----;Path=/;
   x-release-version: 1

【问题讨论】:

    标签: internet-explorer caching internet-explorer-11 browser-cache cache-control


    【解决方案1】:

    首先,Internet Explorer 支持 HTTP 1.1 Cache-Control 标头,当 HTTP 1.1 服务器指定 no-cache 值时,它会阻止对特定 Web 资源的所有缓存。

    其次,Cache-Control HTTP 标头包含用于在 requestsresponses 中进行缓存的指令(指令)。 请求中的给定指令并不意味着响应中应该有相同的指令

    因此,为了防止缓存响应资源,我们可以在响应中设置cache-control: no-cache,并将Expires 设置为“-1”。正如您所说,另一种方法是通过条件 If-Modified-Since 请求更新页面。更多详细信息,请查看这篇文章:How to prevent caching in Internet Explorer

    【讨论】:

    • 我以前读过这个资源。我认为请求标头设置了响应缓存的策略,但事实并非如此。非常感谢!
    【解决方案2】:

    我发现行为取决于标头类型。

    如果我使用cache-control 作为请求的标头,我对所有浏览器都有奇怪的行为。例如,chrome 会忽略除 no-cache 指令之外的所有 cache-control 指令。当我使用 no-cache 指令时,chrome 不会缓存请求。 IE 只是忽略 cache-control 的所有指令,如果它是请求的标头。 因此,请求的标头用于中间代理,但与响应的缓存没有任何连接。

    但是如果我使用缓存控制作为响应的标题,我的行为是正确的,任何指令都可以正常工作。

    就我而言,我无法更改 REST API 并将 cache-control: no-cache 添加到响应中,因为我没有访问权限。但我可以说随时使用请求的标头 If-Modified-Sinse: 0 重新验证缓存的响应。

    【讨论】:

      猜你喜欢
      • 2011-02-27
      • 2020-07-17
      • 2011-01-13
      • 2016-04-26
      • 1970-01-01
      • 1970-01-01
      • 2011-02-05
      • 1970-01-01
      相关资源
      最近更新 更多