How to add source code comments in Thymeleaf templates that don't get included in generated HTML?

I am using full stack Thymeleaf (spring mvc, security, layout dialect, webflow) in a mid-size web application.

Ok..now that we put so much of code in the html templates it would be nice to include source code comments that don't get included in the generated HTML file.

How do we achieve that?


Version 2.1 is released so now you can upgrade your libraries and use comments in your code. With this version developers are able to use parser-level comment blocks:

<!--/* This code will be removed at thymeleaf parsing time! */-->

and prototype-only comment blocks:

<span>hello!</span>
<!--/*/
    <div th:text="${...}">

</div>
/*/-->
<span>goodbye!</span>

Detailed explanation can be found in the official documentation here: http://www.thymeleaf.org/doc/tutorials/2.1/usingthymeleaf.html#comments-and-blocks


As mentioned Rafal Borowiec to comment block of HTML code you should use

<!--/*something to comment*/--> construction (see documentation).

Also it is possible to comment/remove your javascript code using thymeleaf with

/*[- something to comment -]*/ construction (see documentation). So you can annotate your js code without leaking any information

/*[-
 *
 * Some information about function.
 *
 * -]*/
function someFunction() {
    console.log('Hello world');
}

With Thymeleaf 3.0, the currently working version was

<!--/*-->
   this comment will be removed by thymeleaf on the template processing
<!--*/-->

Other answers, for earlier thymeleaf versions, did not work by me. The current thymeleaf documentation is here.