Compressing HTML output

machinedean - 7 months ago

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 - 7 months 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 - 7 months ago

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

machinedean - 7 months ago

Thanks guys, much appreciated.

machinedean - 7 months ago

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

machinedean - 7 months 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 - 7 months 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 - 7 months ago

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

machinedean - 6 months 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 - 6 months ago

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