Purpose
When a browser speculatively loads a resource through prefetch or prerender, the unofficial Purpose request header signals the speculative nature of the request to the server.
Usage
The Purpose header signals to the server when a
request originates from a prefetch or prerender action.
Browsers send the header on requests triggered by
<link rel="prefetch">, <link rel="prerender">, or
the speculation rules API. Servers
receiving this header
distinguish speculative loads from actual user
navigation, allowing them to skip analytics tracking,
defer expensive personalization, or serve lighter
responses for speculative requests.
The header has a long history across browser engines.
Firefox introduced X-Moz: prefetch. Safari used
X-Purpose: preview for its Top Sites page previews.
Chrome adopted Purpose: prefetch as part of its
NoState Prefetch implementation.
The Purpose header is being replaced by
Sec-Purpose, which uses the Sec-
prefix to prevent JavaScript from spoofing the value
through fetch() or XMLHttpRequest. Chrome sent both Purpose and
Sec-Purpose during a transition period.
Current Chrome traffic carries
Sec-Purpose, with the migration away
from Purpose complete in observed requests.
The Purpose header also conflicts with the
CORS specification. Because Purpose is not a CORS
safelisted header, CORS-mode speculative fetches
carrying the header trigger preflight checks. The
Sec- prefix on Sec-Purpose avoids
this because Sec- prefixed names are
forbidden request headers the browser controls,
exempt from author-header preflight rules.
Values
prefetch
The value prefetch indicates the browser is fetching
a resource speculatively. This is the only defined
value. Both prefetch and prerender requests send this
same value in the Purpose header.
Example
A browser prefetching a page using the legacy header. Current Chrome sends Sec-Purpose instead, while older Chromium-based browsers and some other implementations still include this header.
Purpose: prefetch
An older Firefox version prefetching a resource sends
the vendor-specific header. Firefox later replaced
X-Moz with Sec-Purpose.
X-Moz: prefetch
A Chromium-based browser from the transition period sends both header names on the same prefetch request. Checking multiple header names ensures prefetch requests are identified regardless of browser version.
Purpose: prefetch
Sec-Purpose: prefetch
See also
- Pass Sec-Purpose: prefetch with link rel=prefetch (Chrome Status)
- Stop sending Purpose: prefetch (Chrome Status)
- Sec-Purpose
- Speculation Rules
- Sec-Fetch-Dest
- Sec-Fetch-Mode
- HTTP headers