Purpose
When a browser speculatively loads a resource through prefetch or prerender, the 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.
Chrome stopped sending Purpose, completing the
migration to Sec-Purpose.
The Purpose header also conflicts with the
CORS specification. Because Purpose is not a CORS
safelisted header, prefetch requests to cross-origin
resources trigger unnecessary preflight checks. The
Sec- prefix on Sec-Purpose avoids
this because Sec- prefixed headers are excluded from
CORS processing.
Note
Older Firefox versions sent X-Moz: prefetch
before Sec-Purpose replaced it.
Current Firefox sends Sec-Purpose only.
Server-side code detecting prefetch requests
across browsers needs to check for Purpose
and Sec-Purpose, with X-Moz relevant only for
requests from older Firefox versions.
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. Chrome stopped sending Purpose, but older Chromium-based browsers and some other implementations still include the 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