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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
|
---
title: Cache-Control
slug: Web/HTTP/Headers/Cache-Control
translation_of: Web/HTTP/Headers/Cache-Control
---
<div>{{HTTPSidebar}}</div>
<p><strong><code>Cache-Control</code></strong> nagłówek jest stosowany do określania dyrektyw sterujących pamięcią podręczną w zapytaniu i odpowiedzi protokołu HTTP. Dyrektywy pamięci podręcznej są jednokierunkowe, co oznacza że dyrektywa użyta w zapytaniu klienta HTTP nie musi pojawić się w odpowiedzi serwera.</p>
<table class="properties">
<tbody>
<tr>
<th scope="row">Header type</th>
<td>{{Glossary("General header")}}</td>
</tr>
<tr>
<th scope="row">{{Glossary("Forbidden header name")}}</th>
<td>no</td>
</tr>
<tr>
<th scope="row">{{Glossary("Simple response header", "CORS-safelisted response-header")}}</th>
<td>yes</td>
</tr>
</tbody>
</table>
<h2 id="Składnia">Składnia</h2>
<p>Wielkość liter nie ma znaczeniu w określaniu dyrektyw. Dyrektywa może posiadać opcjonalny argument który może być podany jako token (słowo) lub string w cudzysłowiu. Możliwe jest podanie wielu dyrektyw przez oddzielenie ich przecinkiem.</p>
<h3 id="Dyrektywy_zapytania">Dyrektywy zapytania</h3>
<p>Standardowe dyrektywy nagłówka <code>Cache-Control</code> które mogą być użyte w zapytaniu klienta HTTP.</p>
<pre class="syntaxbox">Cache-Control: max-age=<seconds>
Cache-Control: max-stale[=<seconds>]
Cache-Control: min-fresh=<seconds>
Cache-Control: no-cache
Cache-Control: no-store
Cache-Control: no-transform
Cache-Control: only-if-cached
</pre>
<h3 id="Dyrektywy_odpowiedzi">Dyrektywy odpowiedzi</h3>
<p>Standardowe dyrektywy nagłówka <code>Cache-Control</code> które mogą być użyte w odpowiedzi serwera HTTP.</p>
<pre class="syntaxbox">Cache-Control: must-revalidate
Cache-Control: no-cache
Cache-Control: no-store
Cache-Control: no-transform
Cache-Control: public
Cache-Control: private
Cache-Control: proxy-revalidate
Cache-Control: max-age=<seconds>
Cache-Control: s-maxage=<seconds>
</pre>
<h3 id="Extension_Cache-Control_directives">Extension <code>Cache-Control</code> directives</h3>
<p>Extension <code>Cache-Control</code> directives are not part of the core HTTP caching standards document. Be sure to check the <a href="#Browser_compatibility">compatibility table</a> for their support.</p>
<pre class="syntaxbox">Cache-Control: immutable
Cache-Control: stale-while-revalidate=<seconds>
Cache-Control: stale-if-error=<seconds>
</pre>
<h2 id="Directives">Directives</h2>
<h3 id="Cacheability">Cacheability</h3>
<dl>
<dt><code>public</code></dt>
<dd>Indicates that the response may be cached by any cache.</dd>
<dt><code>private</code></dt>
<dd>Indicates that the response is intended for a single user and must not be stored by a shared cache. A private cache may store the response.</dd>
<dt><code>no-cache</code></dt>
<dd>Forces caches to submit the request to the origin server for validation before releasing a cached copy.</dd>
<dt><code>only-if-cached</code></dt>
<dd>Indicates to not retrieve new data. This being the case, the server wishes the client to obtain a response only once and then cache. From this moment the client should keep releasing a cached copy and avoid contacting the origin-server to see if a newer copy exists.</dd>
</dl>
<h3 id="Expiration">Expiration</h3>
<dl>
<dt><code>max-age=<seconds></code></dt>
<dd>Specifies the maximum amount of time a resource will be considered fresh. Contrary to <code>Expires</code>, this directive is relative to the time of the request.</dd>
<dt><code>s-maxage=<seconds></code></dt>
<dd>Overrides <code>max-age</code> or the <code>Expires</code> header, but it only applies to shared caches (e.g., proxies) and is ignored by a private cache.</dd>
<dt><code>max-stale[=<seconds>]</code></dt>
<dd>Indicates that the client is willing to accept a response that has exceeded its expiration time. Optionally, you can assign a value in seconds, indicating the time the response must not be expired by.</dd>
<dt><code>min-fresh=<seconds></code></dt>
<dd>Indicates that the client wants a response that will still be fresh for at least the specified number of seconds.</dd>
<dt><code>stale-while-revalidate=<seconds></code> {{experimental_inline}}</dt>
<dd>Indicates that the client is willing to accept a stale response while asynchronously checking in the background for a fresh one. The seconds value indicates for how long the client is willing to accept a stale response.</dd>
<dt><code>stale-if-error=<seconds></code> {{experimental_inline}}</dt>
<dd>Indicates that the client is willing to accept a stale response if the check for a fresh one fails. The seconds value indicates for how long the client is willing to accept the stale response after the initial expiration.</dd>
</dl>
<h3 id="Revalidation_and_reloading">Revalidation and reloading</h3>
<dl>
<dt><code>must-revalidate</code></dt>
<dd>The cache must verify the status of the stale resources before using it and expired ones should not be used.</dd>
<dt><code>proxy-revalidate</code></dt>
<dd>Same as <code>must-revalidate</code>, but it only applies to shared caches (e.g., proxies) and is ignored by a private cache.</dd>
<dt><code>immutable</code></dt>
<dd>Indicates that the response body will not change over time. The resource, if unexpired, is unchanged on the server and therefore the client should not send a conditional revalidation for it (e.g. <code>If-None-Match</code> or <code>If-Modified-Since</code>) to check for updates, even when the user explicitly refreshes the page. Clients that aren't aware of this extension must ignore them as per the HTTP specification. In Firefox, <code>immutable</code> is only honored on <code>https://</code> transactions. For more information, see also this <a href="http://bitsup.blogspot.de/2016/05/cache-control-immutable.html">blog post</a>.</dd>
</dl>
<h3 id="Other">Other</h3>
<dl>
<dt><code>no-store</code></dt>
<dd>The cache should not store anything about the client request or server response.</dd>
<dt><code>no-transform</code></dt>
<dd>No transformations or conversions should be made to the resource. The Content-Encoding, Content-Range, Content-Type headers must not be modified by a proxy. A non- transparent proxy might, for example, convert between image formats in order to save cache space or to reduce the amount of traffic on a slow link. The <code>no-transform</code> directive disallows this.</dd>
</dl>
<h2 id="Examples">Examples</h2>
<h3 id="Preventing_caching">Preventing caching</h3>
<p>To turn off caching, you can send the following response header. In addition, see also the <code>Expires</code> and <code>Pragma</code> headers.</p>
<pre class="brush: bash">Cache-Control: no-cache, no-store, must-revalidate
</pre>
<h3 id="Caching_static_assets">Caching static assets</h3>
<p>For the files in the application that will not change, you can usually add aggressive caching by sending the response header below. This includes static files that are served by the application such as images, CSS files and JavaScript files, for example. In addition, see also the <code>Expires</code> header.</p>
<pre class="brush: bash">Cache-Control: public, max-age=31536000</pre>
<h2 id="Specifications">Specifications</h2>
<table class="standard-table">
<tbody>
<tr>
<th scope="col">Specification</th>
<th scope="col">Title</th>
</tr>
<tr>
<td>{{RFC("7234")}}</td>
<td>Hypertext Transfer Protocol (HTTP/1.1): Caching</td>
</tr>
<tr>
<td>{{RFC("5861")}}</td>
<td>HTTP Cache-Control Extensions for Stale Content</td>
</tr>
<tr>
<td>{{RFC("8246")}}</td>
<td>HTTP Immutable Responses</td>
</tr>
</tbody>
</table>
<h2 id="Browser_compatibility">Browser compatibility</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.Cache-Control")}}</p>
<h2 id="See_also">See also</h2>
<ul>
<li><a href="/en-US/docs/Web/HTTP/Caching_FAQ">HTTP Caching FAQ</a></li>
<li>{{HTTPHeader("Age")}}</li>
<li>{{HTTPHeader("Expires")}}</li>
<li>{{HTTPHeader("Pragma")}}</li>
</ul>
|