include HX-History-Restore-Request header in history restore requests

This commit is contained in:
carson 2021-02-13 07:35:19 -07:00
parent d71a4b086f
commit edbbaee638
3 changed files with 4 additions and 0 deletions

View File

@ -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

View File

@ -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);

View File

@ -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