diff --git a/CHANGELOG.md b/CHANGELOG.md index 929fdc1b..56ef111b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,8 @@ JSON or javascript via the `javascript:` prefix * `hx-include` will now include all inputs under an element, even if that element is not a form tag * The [preload extension](https://htmx.org/extensions/preload/) now offers a `preload-images="true"` attribute that will aggressively load images in preloaded content +* On requests driven by a history cache miss, the new `HX-History-Restore-Request` header is included so that the server + can differentiate between history requests and normal requests ### Improvements & Bug fixes diff --git a/src/htmx.js b/src/htmx.js index d7139890..4e1a4634 100644 --- a/src/htmx.js +++ b/src/htmx.js @@ -1468,6 +1468,7 @@ return (function () { var details = {path: path, xhr:request}; triggerEvent(getDocument().body, "htmx:historyCacheMiss", details); request.open('GET', path, true); + request.setRequestHeader("HX-History-Restore-Request", "true"); request.onload = function () { if (this.status >= 200 && this.status < 400) { triggerEvent(getDocument().body, "htmx:historyCacheMissLoad", details); diff --git a/www/reference.md b/www/reference.md index efbeec2e..9bf24c58 100644 --- a/www/reference.md +++ b/www/reference.md @@ -70,6 +70,7 @@ title: htmx - Attributes | Header | Description | |-------|-------------| | `HX-Current-URL` | the current URL of the browser +| `HX-History-Restore-Request` | `true` if the request is for history restoration after a miss in the local history cache | `HX-Prompt` | the user response to an [hx-prompt](/attributes/hx-prompt) | `HX-Request` | always `true` | `HX-Target` | the `id` of the target element if it exists