Compressing HTML output
Created 7 years ago by machinedeanHi 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!
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).
Thanks guys, much appreciated.
Thank you William! I did search on the forum but I didn't spot this one.
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?
@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.
Thanks Ryan. That all makes sense, we'll update soon and implement.
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.
@machinedean look out for deferred
blocks as they appear to not be compatible. Is this what you're seeing?
https://twig.sensiolabs.org/doc/2.x/tags/spaceless.html Not that?