Skip to content

Feature request: preserve_thymeleaf_template_syntax option #274

@HowieHz

Description

@HowieHz

Hi, thanks for this excellent project.

I'd like to request support for Thymeleaf template syntax preservation.

Background

minify-html already supports preserving several template syntaxes through:

  • preserve_brace_template_syntax
  • preserve_chevron_percent_template_syntax

However, Thymeleaf uses different markers that aren't currently recognized.

The Problem

Aggressive minification can silently break Thymeleaf templates. In practice, users end up having to skip minification entirely for any file containing Thymeleaf-sensitive syntax, which pretty much defeats the purpose of using minify-html in Thymeleaf-based projects.

Syntax That Needs to Be Preserved

One of Thymeleaf's core design goals is Natural Templates — templates that can be opened directly in a browser as static prototypes, while still being processed correctly by Thymeleaf on the server. This relies on several special syntax forms that must survive minification intact:

  1. JavaScript / CSS inline expressions (inside blocks with th:inline="javascript" or th:inline="css"):

    • /*[[ ... ]]*/ — escaped output
    • /*[( ... )]*/ — unescaped output
    • /*[# th:each="..."] ... /*[/]*/ — inline blocks, where /*[# ...]*/ is the opening marker and /*[/]*/ is the closing marker
  2. Advanced inlining features (also inside th:inline blocks):

    • /*[+ ... +]*/ — inlined code (only active when processed by Thymeleaf)
    • /*[- ... -]*/ — inlined code removal (only visible in static prototypes)
  3. Prototype-only comment blocks (in regular HTML):

    • <!--/*/ ... /*/--> — hidden as an HTML comment when opened statically, but treated as normal markup by Thymeleaf at runtime

Suggested Support

It would be great if minify-html could add a Thymeleaf-aware preservation mode, for example via:

  • a dedicated config option like preserve_thymeleaf_template_syntax
  • or a more generic API for registering custom delimiter pairs / preservation markers

A generic custom-delimiter mechanism would also work well if full Thymeleaf support is out of scope.

Why This Matters

Thymeleaf is widely used in the Java ecosystem, especially in Spring applications. Better preservation support would make minify-html significantly more practical for server-rendered Java templates.

Thanks!

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