--- title: Cache-Control slug: Web/HTTP/Headers/Cache-Control translation_of: Web/HTTP/Headers/Cache-Control ---
Cache-Control 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.
| Header type | {{Glossary("General header")}} |
|---|---|
| {{Glossary("Forbidden header name")}} | no |
| {{Glossary("Simple response header", "CORS-safelisted response-header")}} | yes |
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.
Standardowe dyrektywy nagłówka Cache-Control które mogą być użyte w zapytaniu klienta HTTP.
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
Standardowe dyrektywy nagłówka Cache-Control które mogą być użyte w odpowiedzi serwera HTTP.
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>
Cache-Control directivesExtension Cache-Control directives are not part of the core HTTP caching standards document. Be sure to check the compatibility table for their support.
Cache-Control: immutable Cache-Control: stale-while-revalidate=<seconds> Cache-Control: stale-if-error=<seconds>
publicprivateno-cacheonly-if-cachedmax-age=<seconds>Expires, this directive is relative to the time of the request.s-maxage=<seconds>max-age or the Expires header, but it only applies to shared caches (e.g., proxies) and is ignored by a private cache.max-stale[=<seconds>]min-fresh=<seconds>stale-while-revalidate=<seconds> {{experimental_inline}}stale-if-error=<seconds> {{experimental_inline}}must-revalidateproxy-revalidatemust-revalidate, but it only applies to shared caches (e.g., proxies) and is ignored by a private cache.immutableIf-None-Match or If-Modified-Since) 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, immutable is only honored on https:// transactions. For more information, see also this blog post.no-storeno-transformno-transform directive disallows this.To turn off caching, you can send the following response header. In addition, see also the Expires and Pragma headers.
Cache-Control: no-cache, no-store, must-revalidate
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 Expires header.
Cache-Control: public, max-age=31536000
| Specification | Title |
|---|---|
| {{RFC("7234")}} | Hypertext Transfer Protocol (HTTP/1.1): Caching |
| {{RFC("5861")}} | HTTP Cache-Control Extensions for Stale Content |
| {{RFC("8246")}} | HTTP Immutable Responses |
The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
{{Compat("http.headers.Cache-Control")}}