blob: 46ccab97ceced75c07dcbd1d1de479d1c4d79aed (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
---
title: Access-Control-Max-Age
slug: Web/HTTP/Headers/Access-Control-Max-Age
tags:
- 超文本传输协议
- 跨域资源请求
- 首部
translation_of: Web/HTTP/Headers/Access-Control-Max-Age
---
<div>{{HTTPSidebar}}</div>
<p>The <strong><code>Access-Control-Max-Age</code></strong> 这个响应头表示 {{glossary("preflight request")}} (预检请求)的返回结果(即 {{HTTPHeader("Access-Control-Allow-Methods")}} 和{{HTTPHeader("Access-Control-Allow-Headers")}} 提供的信息) 可以被缓存多久。</p>
<table class="properties">
<tbody>
<tr>
<th scope="row">报头类型</th>
<td>{{Glossary("Response header")}}</td>
</tr>
<tr>
<th scope="row">{{Glossary("Forbidden header name")}}</th>
<td>no</td>
</tr>
</tbody>
</table>
<h2 id="语法">语法</h2>
<pre class="syntaxbox">Access-Control-Max-Age: <delta-seconds>
</pre>
<h2 id="指令">指令</h2>
<dl>
<dt><delta-seconds></dt>
<dd>返回结果可以被缓存的最长时间(秒)。<br>
在 Firefox 中,<a href="https://dxr.mozilla.org/mozilla-central/rev/7ae377917236b7e6111146aa9fb4c073c0efc7f4/netwerk/protocol/http/nsCORSListenerProxy.cpp#1131">上限是24小时</a> (即 86400 秒)。<br>
在 Chromium v76 之前, <a href="https://cs.chromium.org/chromium/src/services/network/public/cpp/cors/preflight_result.cc?l=36&rcl=52002151773d8cd9ffc5f557cd7cc880fddcae3e">上限是 10 分钟</a>(即 600 秒)。<br>
从 Chromium v76 开始,<a href="https://cs.chromium.org/chromium/src/services/network/public/cpp/cors/preflight_result.cc?l=31&rcl=49e7c0b4886cac1f3d09dc046bd528c9c811a0fa">上限是 2 小时</a>(即 7200 秒)。<br>
Chromium 同时规定了一个默认值 5 秒。<br>
如果值为 <strong>-1</strong>,表示禁用缓存,则每次请求前都需要使用 OPTIONS 预检请求。</dd>
</dl>
<h2 id="示例">示例</h2>
<p>将预检请求的结果缓存10分钟:</p>
<pre>Access-Control-Max-Age: 600 </pre>
<h2 id="规范">规范</h2>
<table class="standard-table">
<tbody>
<tr>
<th scope="col">规范</th>
<th scope="col">状态</th>
<th scope="col">注释</th>
</tr>
<tr>
<td>{{SpecName('Fetch','#http-access-control-max-age', 'Access-Control-Max-Age')}}</td>
<td>{{Spec2("Fetch")}}</td>
<td>Initial definition.</td>
</tr>
</tbody>
</table>
<h2 id="浏览器兼容性">浏览器兼容性</h2>
<p class="hidden">The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out <a href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> and send us a pull request.</p>
<p>{{Compat("http.headers.Access-Control-Max-Age")}}</p>
<h2 id="相关内容">相关内容</h2>
<ul>
<li>{{HTTPHeader("Access-Control-Allow-Headers")}}</li>
<li>{{HTTPHeader("Access-Control-Allow-Methods")}}</li>
</ul>
|