Skip to content

Pragma

Description

The Pragma response header is an implementation-specific header that may have various effects along the request-response chain. It's primarily used for backwards compatibility with HTTP/1.0 caches where the Cache-Control header is not yet understood.

In modern HTTP, the Pragma header is mostly used with the value no-cache to ensure that responses are not cached by HTTP/1.0 caches. This works in conjunction with HTTP/1.1's Cache-Control: no-cache directive but extends the no-caching behavior to older systems.

While Pragma was more significant in the transition period from HTTP/1.0 to HTTP/1.1, it is still included in many responses today to ensure maximum compatibility across all client types. However, for HTTP/1.1 and newer clients, the Cache-Control header provides more precise and feature-rich cache control mechanisms.

Syntax

The syntax of the Pragma header follows this structure:

Pragma: no-cache

The only standardized value for the Pragma header is no-cache, though other implementation-specific values may exist.

Example Syntax

Pragma: no-cache

This example directs HTTP/1.0 caches not to cache the response.

Examples

Basic No-Cache Example

A response that should not be cached by any cache, including HTTP/1.0 caches:

HTTP/1.1 200 OK
Date: Mon, 02 Jun 2025 14:00:00 GMT
Content-Type: application/json
Cache-Control: no-cache, no-store, must-revalidate
Pragma: no-cache
Expires: 0
Content-Length: 54

{
  "timestamp": 1717412400,
  "random": "abc123def456"
}

In this example, the combination of Cache-Control, Pragma, and Expires headers ensures that the response is not cached by any client or intermediary, regardless of which HTTP version they support.

Combined with ETag Example

A response that uses ETags for validation but should not be cached without validation:

HTTP/1.1 200 OK
Date: Mon, 02 Jun 2025 14:10:30 GMT
Content-Type: text/html
Cache-Control: no-cache
Pragma: no-cache
ETag: "abc123def456"
Content-Length: 1234

<!DOCTYPE html>
<html>
<head><title>Dynamic Content</title></head>
<body><p>This content may change frequently.</p></body>
</html>

In this example, the no-cache directive in both Cache-Control and Pragma headers indicates that the client should validate the cached copy with the server before using it, even if it's still fresh according to other cache control mechanisms.

Mixed Client Support Example

A response designed to work across HTTP versions:

HTTP/1.1 200 OK
Date: Mon, 02 Jun 2025 14:20:45 GMT
Content-Type: text/css
Cache-Control: public, max-age=3600
Pragma: no-cache
Expires: Mon, 02 Jun 2025 15:20:45 GMT
Content-Length: 567

body {
  font-family: Arial, sans-serif;
  color: #333;
}
/* ... more CSS ... */

This example shows a somewhat contradictory set of headers: Cache-Control allows caching for one hour in HTTP/1.1 clients, while Pragma: no-cache tells HTTP/1.0 clients not to cache at all. This inconsistency highlights the challenges of supporting different HTTP versions and the importance of understanding how different headers interact.

Summary

The Pragma response header serves primarily as a backward compatibility mechanism for HTTP/1.0 caches, with its main standardized use being the no-cache directive. While less relevant in modern web development due to the widespread adoption of HTTP/1.1 and newer versions with their more sophisticated Cache-Control header, Pragma: no-cache is still commonly included in responses to ensure maximum compatibility with all possible clients and intermediaries. When implementing caching strategies, it's good practice to include both Cache-Control and Pragma headers when you want to prevent caching, ensuring consistent behavior across different HTTP versions.