How to exclude certain html tags from minification?

Hi there,

How can i tell hugo to not remove or minify the below html tag

<!--sse-->This text conditional <!--/sse-->


Configure Minify
maybe that help.

You can keep comments, but doubt you can just specify what need and what don’t to be minified.

      keepComments = false

Hi @idarek

Turning comments off is one way. However, this is not the traditional comment. It serves as a wrapper to conditionally display specific text to site visitors while hiding it from bots.

Is there anything available that indicates to Hugo that this comment is essential and shouldn’t be changed or removed? or whitelist specific HTML tags to indicate that the code <!--sse--> should not be changed.



 keepConditionalComments = true

and modify your code to use conditional comments

But that’s not a good solution and doubt that there are. Comments are for comments. If you using this for other purposes, there are other tags that you can use that you can display: hidden from visitors etc.

{{"<!-- Your comment here -->" | safeHTML }}


Hi @willduncanphoto

It doesn’t work comments are removed even when in the safeHTML.


Hi @idarek

I am using Cloudflare. Cloudflare decides if the visitor is a bot or not, and accordingly displays the conditional content. Cloudflare has a very specific tag you have to use, which is <!--sse-->.

If at all possible, an exception to this rule will enable the addition of conditional comments while maintaining the other optimizations for comment removal and minification.


Replace the exclamation mark with its HTML entity.

In a template:

{{ "<&#33;--sse-->foo<&#33;--/sse-->" | safeHTML }}

Thanks @jmooring

It works!

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.