Skip to content

cache compiled eval tags in safeEval feature for better hx-live perf#3888

Open
MichaelWest22 wants to merge 1 commit into
bigskysoftware:four-devfrom
MichaelWest22:csp-eval-cache
Open

cache compiled eval tags in safeEval feature for better hx-live perf#3888
MichaelWest22 wants to merge 1 commit into
bigskysoftware:four-devfrom
MichaelWest22:csp-eval-cache

Conversation

@MichaelWest22

Copy link
Copy Markdown
Collaborator

Description

Found that hx-csp creates temporary script tags via its safeEval feature but when using things like hx-live this means it re-creates the same eval script each dom update. We can easily cache the functions and reuse them so they do not need to be be re-created every time.

Corresponding issue:

Testing

Tested this manually in a test project to confirm faster performance during events. It went from ~2ms to fire a small batch of expressions down to ~1.2ms. before safe-eval was a bit slower by design than normal eval but now it is just a little bit faster but the perf difference is hard to notice comparing the two.

Checklist

  • I have read the contribution guidelines
  • I have targeted this PR against the correct branch (master for website changes, dev for
    source changes)
  • This is either a bugfix, a documentation update, or a new feature that has been explicitly
    approved via an issue
  • I ran the test suite locally (npm run test) and verified that it succeeded

@MichaelWest22 MichaelWest22 added the htmx 4 Issues specific to htmx version 4 label Jul 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

htmx 4 Issues specific to htmx version 4

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant