Generating minified XHTML


I’m working on an epub theme inspired from emk’s share (many thanks for getting me started!). Everything is working and now I’d like to minify the generated output to minimize the size of my files. And I hit a snag.

Basically, I generate XHTML files, which I defined as custom output formats. They are defined as HTML, so tdewolff minifies it with HTML rules. However, there is one problem with those rules:

  • tdewolff removes the “/” at the end of unary tags (<img src="">).
  • XHTML is less lax and wants this “/” (<item href="" />).

I suppose everything would work fine if I could tell Hugo to minify using XML rules instead of HTML.

Is there a way to tell Hugo “this output format should be minified as XML/HTML/JS”? If not, is it worth suggesting as a feature, and is it only feasible in Hugo?

Generating minified XHTML

Read the DOC :wink:

1 Like

tdewolff/minify cannot minify XHTML. You can either disable minimization or handle it with a secondary process.


Thanks, I did, exhaustively, before even asking. I also tinkered with those options to try and get it work. Bothering the community is a last resort in my book.

“RTFM” is a valid answer, when the answer is in the doc. Getting people used to read the docs is a good thing, it saves time. If you want to be constructive, though, you can highlight the specific passage that answers the question and give an example, especially when the question is as specific as mine. Had you done for this question, you’d seen it does not apply in my case. If you read the page yourself, you’ll see there’s no mention of XHTML or trailing slashes in unary tags.

Thanks for having a look at my question, though.

1 Like

I made a feature proposal on Hugo’s Github, the developers will determine if it’s a relevant use case now.