Skip to content

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:

Pragma: no-cache

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:

GET /data.json HTTP/1.1
Host: example.com
Pragma: no-cache

Server Response:

HTTP/1.1 200 OK
Content-Type: application/json
Cache-Control: no-cache

{"data": "fresh content"}

Using Pragma in a Response (Discouraged in HTTP/1.1)

A server includes the Pragma header in its response.

Server Response:

HTTP/1.1 200 OK
Content-Type: text/html
Pragma: no-cache

<html>...</html>

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:

GET /page.html HTTP/1.1
Host: example.com
Pragma: no-cache
Cache-Control: no-cache

Server Response:

HTTP/1.1 200 OK
Content-Type: text/html
Cache-Control: no-cache, no-store

<html>...</html>

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.