Class HtmxRequestHeaderNames
- Namespace
- Ramstack.HtmxToolkit
- Assembly
- Ramstack.HtmxToolkit.dll
Defines constants for the well-known names of HTMX request headers.
public static class HtmxRequestHeaderNames
- Inheritance
-
HtmxRequestHeaderNames
- Inherited Members
Examples
// The same URL returns a page or a fragment depending on these headers,
// so they must be part of the output cache key.
builder.Services.AddOutputCache(options =>
{
options.AddPolicy("HtmxHtml", policy => policy.SetVaryByHeader(
HtmxRequestHeaderNames.Request,
HtmxRequestHeaderNames.HistoryRestoreRequest,
HtmxRequestHeaderNames.RequestType));
});
Remarks
For more information, see HTMX Request Headers Reference.
Fields
Boosted
The HX-Boosted header indicates that the request came from a link or form
enhanced with hx-boost.
public const string Boosted = "HX-Boosted"
Field Value
CurrentUrl
The HX-Current-URL header contains the current URL of the browser.
public const string CurrentUrl = "HX-Current-URL"
Field Value
HistoryRestoreRequest
The HX-History-Restore-Request header indicates whether the request
fetches content for history restoration.
public const string HistoryRestoreRequest = "HX-History-Restore-Request"
Field Value
Remarks
HTMX 1.x and 2.x send this header after a history cache miss. HTMX 4.x refetches history content by default; local caching requires an extension.
Prompt
The HX-Prompt header contains the user's response to an hx-prompt.
public const string Prompt = "HX-Prompt"
Field Value
Remarks
Supported natively in HTMX 1.x and 2.x. In HTMX 4.x, the hx-prompt extension restores this header.
Request
The HX-Request header indicates that the request was issued by HTMX.
Its value is always "true".
public const string Request = "HX-Request"
Field Value
RequestType
The HX-Request-Type header indicates whether the request expects a partial
or a full page response.
public const string RequestType = "HX-Request-Type"
Field Value
Remarks
The value is "partial" for targeted swaps and "full" for body-level
or hx-select requests. HTMX 4.x sends the header itself; for HTMX 1.x and 2.x,
the companion script htmx-toolkit.js adds it.
Source
The HX-Source header identifies the element that triggered the request.
public const string Source = "HX-Source"
Field Value
Remarks
Supported only in HTMX 4.x. The value contains the lowercase tag name and,
when the element has an ID, # followed by its URI-encoded ID.
Examples include button#submit and button.
Target
The HX-Target header identifies the target element, if present.
public const string Target = "HX-Target"
Field Value
Remarks
In HTMX 1.x and 2.x, the value is the ID of the target element.
In HTMX 4.x, the value contains the lowercase tag name and, when the element has an ID,
# followed by its URI-encoded ID. Examples include div#results and body.
Trigger
The HX-Trigger header contains the ID of the element that issued the request, if present.
public const string Trigger = "HX-Trigger"
Field Value
Remarks
Supported only in HTMX 1.x and 2.x. HTMX 4.x identifies the source element with HX-Source instead.
TriggerName
The HX-Trigger-Name header contains the name attribute of the element
that issued the request, if present.
public const string TriggerName = "HX-Trigger-Name"
Field Value
Remarks
Supported only in HTMX 1.x and 2.x. HTMX 4.x identifies the source element with HX-Source instead.