Sec-Speculation-Tags
The HTTP Sec-Speculation-Tags request header identifies which developer-defined tags are associated with a speculative navigation request, allowing servers and intermediaries to distinguish between different sources of speculation rules.
Usage
The Sec-Speculation-Tags header carries tag values
from speculation rules triggering a prefetch or
prerender request. When a developer adds a tag field
to a speculation rule or ruleset, the browser collects
all matching tags, deduplicates them, sorts them
lexicographically, and sends them in this header on the
speculative request.
The header complements Sec-Purpose, which identifies the type of speculation (prefetch or prerender) but not its source. A CDN injecting speculation rules and a site owner adding their own rules both generate speculative requests, and without Sec-Speculation-Tags the server has no way to tell which rules triggered which request.
A primary use case is CDN-level speculation filtering. A CDN inserts speculation rules tagged with its identifier. When the origin server receives a prefetch request carrying the CDN's tag, the server serves cached content or blocks the speculation. Requests from the site owner's rules carry different tags (or no tag) and pass through normally.
The tag field appears at two levels in the
speculation rules JSON:
- Ruleset level (top-level
tagproperty): applies to all rules in the ruleset. Safe to use in browsers without support for the field, since unknown top-level properties are ignored. - Individual rule level (
taginside a rule object): applies to the specific rule only. In older browsers not recognizing the field, the entire rule is silently dropped.
When multiple rules match the same URL, the browser
combines their tags. If any matching rule has no tag,
the predefined token null appears alongside the
developer-defined string tags.
The browser sends Sec-Speculation-Tags only on
same-site speculative navigation requests. Cross-site
requests omit the header to prevent using tags as a
cross-site communication channel. The Sec- prefix
prevents JavaScript from setting or modifying the
header through fetch(), XMLHttpRequest, or service
workers.
Note
Sec-Speculation-Tags is supported in Chromium-based browsers. The header requires a secure context (HTTPS).
Values
The header value is a Structured Fields List. Members are either strings (developer- defined tags in double quotes) or tokens (predefined values).
String tags
Developer-defined tag strings from the tag field in
speculation rules. Multiple string tags are comma-
separated and sorted lexicographically.
null
The null token (a bare token, not a quoted string)
indicates a speculative navigation request from a rule
with no developer-defined tag. When every matching rule
has an explicit tag, null does not appear.
Example
A CDN injects tagged speculation rules alongside the site owner's rules. The tag identifies the CDN as the source.
{
"tag": "awesome-cdn",
"prefetch": [{
"eagerness": "conservative",
"where": {
"href_matches": "/*",
"relative_to": "document"
}
}]
}
The resulting prefetch request carries the CDN's tag. The origin server checks the tag to decide whether to serve the speculation from cache or block the request.
Sec-Purpose: prefetch
Sec-Speculation-Tags: "awesome-cdn"
A speculation rule with no tag. The browser sends the
predefined null token.
Sec-Speculation-Tags: null
When two rules match the same URL, one with a tag and one without, the browser combines both values.
Sec-Speculation-Tags: null, "cdn-prefetch"
A ruleset-level tag combined with a rule-level tag. Both tags appear in the header.
Sec-Speculation-Tags: "my-rule", "my-ruleset"
A prerender request with both Sec-Purpose and Sec-Speculation-Tags present. The server distinguishes the speculation type and its source.
Sec-Purpose: prefetch;prerender
Sec-Speculation-Tags: "my-rules"
Sec-Fetch-Dest: document
Takeaway
The Sec-Speculation-Tags header identifies the source of speculative navigation requests by carrying developer-defined tags from speculation rules, enabling servers and intermediaries to filter or route speculations based on which rules triggered them.
See also
- WHATWG HTML: Speculative Loading
- Speculation Rules Tags Explainer (WICG)
- Sec-Purpose
- Speculation Rules
- No-Vary-Search
- HTTP headers