What Is Cache-Control

Cache-Control is an HTTP header telling the browser, proxy, or CDN how to cache or respond to requests (no-store response included). It is used to control the caching of resources, such as websites, images, and other media files.

It can also include information about the maximum time that a packet is allowed to remain in the network before it is discarded (TTL).

Most common cache control directives

The Cache-Control header can mention quite a few response directives, such as:

Public header

Any cache may cache the response (shared caches included).

Private header

The response is intended for a single user and its storage, and no shared cache can cache the content.

No-cache header

Surprisingly it doesn’t mean “no content caching at all”. It says to check with the server if there’s a new copy of the object is available before the cache can be used.

No-store header

No-store header instructs the browser not to store the content in any cache. To put it simply – no caching at all.

The Cache-Control header is used to improve the performance of web applications by reducing the amount of data that needs to be transmitted over the network. By correctly specifying the caching directives, web developers can ensure that resources are cached appropriately and are served to clients from the cache when possible, reducing the load on the server and improving the overall performance of the application.

CDN Cache-Control

CDNs use various techniques to speed up the delivery of content, such as images and other media files on servers closer to the original location of the end-user. By using cache control headers, web developers can have more control over how resources are served from a CDN and can ensure that users are getting the desired version of a resource.

In a Content Delivery Network (CDN), when the user sends the request, the CDN checks to see if it has the most recent copy of the resource stored in its cache. If it does, it will return the cached copy to the client, rather than requesting it from the origin server.

The CDN uses cache control headers to determine how long a resource should be stored in the cache and whether it should be revalidated before use. For example, the Cache-Control header can be used to specify that a resource should be cached for a certain amount of time, or that it should not be cached at all. The Expires HTTP header can specify the time when the resource should no longer be considered fresh and thus needs revalidation.