Compressing HTML output
Created 5 years ago by machinedean

Hi all, apologies if I've missed something in the documentation but I cannot see an obvious way to minify HTML output. I know there are various Laravel packages out there but given that Pyro uses twig templates I'm not sure whether these will be supported. Thanks in advanced!

ryanthompson  —  5 years ago

Spaceless is all I've got right now but I am open to improvements. I feel like spaceless is probably the easies to incorporate though for sure (at the moment).

piterden  —  5 years ago

If you want to optimize the size of the generated HTML content, gzip compress the output instead.

machinedean  —  5 years ago

Thanks guys, much appreciated.

machinedean  —  5 years ago

Thank you William! I did search on the forum but I didn't spot this one.

machinedean  —  5 years ago

Hi, apologies for the slow reply. I've tried both spaceless and and neither are minifying the HTML on the page. Any ideas why this might be happening?

ryanthompson  —  5 years ago

@machinedean just wrap your HTML with {% htmlcompress %} like this:

Note though - do NOT use defer on any internal blocks. It seems to not play well with the compression.

You don't need to include this yourself anymore core comes with htmlcompress now.

machinedean  —  5 years ago

Thanks Ryan. That all makes sense, we'll update soon and implement.

machinedean  —  4 years ago

Just to let you know, {% htmlcompress %} and {% endhtmlcompress %} work great now it's included in the core but for some reason doesn't work in my layouts (default.twig for example) unless I move it within the body tags. I can work around it and manually compress the HTML above the body tags so it doesn't matter too much.

It works fine in all other partials etc.

ryanthompson  —  4 years ago

@machinedean look out for deferred blocks as they appear to not be compatible. Is this what you're seeing?