Compressing HTML output
Created 7 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  —  7 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  —  7 years ago

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

machinedean  —  7 years ago

Thanks guys, much appreciated.

machinedean  —  7 years ago

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

machinedean  —  7 years ago

Hi, apologies for the slow reply. I've tried both spaceless and https://pyrocms.com/forum/channels/tips/how-to-minimize-html-output and neither are minifying the HTML on the page. Any ideas why this might be happening?

ryanthompson  —  7 years ago

@machinedean just wrap your HTML with {% htmlcompress %} like this: https://github.com/anomalylabs/streams-platform/blob/1.2/resources/stubs/addons/resources/views/layouts/default.twig

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

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

machinedean  —  7 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  —  7 years ago

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