How is's HTML so clean from whitespace and newlines?

Example: view-source:

It’s my assumption that this is done in a post-processing step rather than as part of Hugo’s rendering, so perhaps this should be a feature request rather than a support request. I figured that I’m not the only one who has asked that question though, and that this would be a good enough place to start that conversation.

Tangentially related; Go 1.6 is able to suppress newlines, and the inclusion of that feature in Hugo 0.16 will certainly help with writing clean templates, once it’s released.

To clean and minify the HTML, CSS and Javascript files I use minify: With just one comman it completely minifies all files in the public folder.

1 Like

@MartinHerbst this (go minify) is a cool project. Thanks for sharing. I wonder if this could be part of future Hugo versions and added to the build step.

@rdwatters there is already and issue about minifying vs compression (gzip)

+1 for @MartinHerbst 's response. I’ve been a Jekyll user and love that CMS too. Jekyll also has an asset pipeline that helps you out as you go, like processing Sass files into .CSS. However, I want 100% control over asset optimization and management. For that I use NPM and Bower for asset management and Gulp or Grunt for running asset pipeline tasks (including minimization). The task managers have plenty of integration options and the task runners have fantastic collections of plugins. Chances are if you think of an optimization, it’s already been written with the Gulp or Grunt task runners.

So, I actually dig that Hugo doesn’t try to help me in such ways. It is a separate effort to set things up using these tools, but there’s nothing in Hugo that’ll get in your way if you choose that path. For my Jekyll sites, I sometimes need to perform some automation-acrobatics to not conflict with Jekyll’s native functionality.

Bottom line is that all you could want has been already written in tools that have pretty easy integration.

Hope that helps!