htmx/www/content/attributes/hx-history.md
William Jackson 46badfe0b1
Add descriptions for attribute pages (#3158)
Descriptions for attribute pages
2025-02-07 17:07:13 -07:00

1.0 KiB

+++ title = "hx-history" description = """
The hx-history attribute in htmx allows you to prevent sensitive page data from being stored in the browser's
localStorage cache during history navigation, ensuring that the page state is retrieved from the server instead when
navigating through history.""" +++

Set the hx-history attribute to false on any element in the current document, or any html fragment loaded into the current document by htmx, to prevent sensitive data being saved to the localStorage cache when htmx takes a snapshot of the page state.

History navigation will work as expected, but on restoration the URL will be requested from the server instead of the history cache.

Here is an example:

<html>
<body>
<div hx-history="false">
 ...
</div>
</body>
</html>

Notes

  • hx-history="false" can be present anywhere in the document to embargo the current page state from the history cache (i.e. even outside the element specified for the history snapshot hx-history-elt).