Cache-Control Header
Table of Content
The Cache-Control
HTTP header is a crucial tool that controls how, or if, a network client caches the response. It allows a client or server to transmit several directives in its HTTP responses, which dictate the browser caching policies in both client and server-side. The directives are specific to each object in the response, allowing high customization and flexibility in the caching mechanism.
Syntax
Cache-Control: <directive>
Where <directive>
is the value of a specific caching directive.
Directives
Public: It defines the response can be cached by any cache, even if the response is usually non-cacheable or associates with HTTP authentication.
Private: This specifies that the response is specifically for a single user and must not be stored in a shared cache.
No-Cache: It forces caches to submit the request to the origin server for validation.
No-Store: The most strict directive, insisting that the response must not be cached.
Examples
Cache-Control: no-cache, must-revalidate
Cache-Control: max-age=3600
Cache-Control: private, max-age=600
Browser Compatibility
Browser | Compatibility |
---|---|
Chrome | Supported |
Firefox | Supported |
Safari | Supported |
Opera | Supported |
Edge | Supported |
How to modify Cache-Control header
ModHeader
is an extension available for Google Chrome browsers that allows developers to customize HTTP request and response headers, which includes modifying the Cache-Control
directives.
- Install the ModHeader extension from the Chrome Web Store.
- Once installed, click the ModHeader icon in the toolbar.
- In the drop-down list, click the
+
icon, addCache-Control
in the header name input box, and fill your directive in value input. Likeno-cache, must-revalidate
.
With this, you've modified the Cache-Control
header for your requests. It's useful when you want to control how resources are cached on a client or server or when testing different caching policies and analyzing their outcomes.