Skip to content

Alpine.js + HTMX integration breaks due to lowercased event attributes (@htmx:afterOnLoad → @htmx:afteronload) #246

@CDU-Ge

Description

@CDU-Ge

Problem
When using minify-html, attributes like @htmx:afterOnLoad — which are used in Alpine.js for event binding — are automatically lowercased to @htmx:afteronload. This causes Alpine.js to no longer recognize the event, because event attribute names are case-sensitive in Alpine.js.

Example input (original, works):

<button
  hx-get="/api/data"
  hx-swap="none"
  @htmx:afterOnLoad="doSomething()"
>
  Refresh
</button>

Minified output (broken):

<button
  hx-get="/api/data"
  hx-swap="none"
  @htmx:afteronload="doSomething()"
>
  Refresh
</button>

This breaks Alpine.js functionality, because @htmx:afteronload is not the same event as @htmx:afterOnLoad.


Why this matters
This issue affects anyone using HTMX + Alpine.js together — a common lightweight frontend combo — especially for binding to HTMX lifecycle events.

Other impacted use cases:

  • Web components using camelCase properties or event handlers
  • Frameworks expecting specific casing (e.g. Vue custom directives)
  • JSX SSR hydration mismatches
  • Any case-sensitive data-* or custom attribute conventions

Suggested fix
Add a new option:

preserve_attribute_case: true

When enabled, this option would prevent minify-html from converting attribute names to lowercase, preserving compatibility with case-sensitive frontend environments.


Environment

  • minify-html version: (fill in)
  • Usage: (CLI / Rust / WASM / Python)
  • Frontend: Alpine.js + HTMX

Related keywords

  • @htmx:afterOnLoad case issue
  • alpine.js event binding
  • camelCase attributes
  • attribute lowercasing breaks behavior
  • preserve attribute case

Closing note
Even though HTML treats attribute names as case-insensitive, JavaScript frameworks don’t, and preserving attribute casing is essential for modern frontend tooling.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions