Pragma
Description
The Pragma
request header is an HTTP/1.0 header used for backward
compatibility with older caches. It is primarily employed to control caching
behavior, though its function has been largely replaced by the Cache-Control
header in HTTP/1.1.
The most common directive associated with Pragma
is no-cache
, which
instructs caches to revalidate the resource with the origin server before
serving a cached copy. However, Pragma
is not consistently implemented across
all HTTP versions, and its behavior can vary depending on the client and server
configuration.
Although Pragma
is mainly a request header, it can also appear in responses.
However, HTTP/1.1 recommends using Cache-Control
instead.
Syntax
The Pragma
header is used in an HTTP request as follows:
This directive tells intermediate caches and proxies not to serve a cached response without first checking with the origin server.
Examples
Preventing Cached Responses
A client requests a resource while ensuring that it is revalidated with the origin server.
Client Request:
Server Response:
Using Pragma in a Response (Discouraged in HTTP/1.1)
A server includes the Pragma
header in its response.
Server Response:
Although this is valid, Cache-Control
should be used instead in modern HTTP
implementations.
Combined Usage with Cache-Control
A client uses both Pragma
and Cache-Control
to ensure compatibility with
HTTP/1.0 and HTTP/1.1 caches.
Client Request:
Server Response:
Summary
The Pragma
request header is a legacy HTTP/1.0 mechanism for controlling cache
behavior, mainly used to enforce revalidation of cached resources. While still
seen in some implementations for backward compatibility, it has been largely
superseded by the more robust Cache-Control
header in HTTP/1.1. For modern
applications, Cache-Control
should be preferred to ensure consistent caching
behavior across different clients and proxies.