When testing my Symfony 2.8
based webpage with Google PageSpeed Insights I am getting warned, that the HTML code is not minified.
This is true, while Assetic
takes care of minifying all CSS
files and JS
scripts, the HTML code itself is quite dirty.
Google recommends to use HTML Minifier, but since this a JavaScript tools it cannot be used as Twig
extension, filter, etc., can it?
The Twig
docu of the spaceless
tag makes clear, that this tag is not meant to minify HTML and furthmore:
If you want to create a tag that actually removes all extra whitespace in an HTML string, be warned that this is not as easy as it seems to be (think of textarea or pre tags for instance). Using a third-party library like Tidy is probably a better idea.
But again I don't see how Tidy
could be integrated into the Twig
templates, etc.
So, what is the best way, to create minified HTML output with Symfony
and Twig
?