Optimize your html with twig

Here is one cool trick I learned this week which will help you optimize your website if you are using the twig templating engine.
Timber-twig is one of my must use plugins for wordpress theme development.
During the deployment I often used to get help of plugins such as W3totalCache for html minification on the fly. This is also a great tool (You should definitely try if you never have done before).
You can still gzip the output to optimize the size of your html document.
I’m very happy to discover that feature in twig since it will generate already minified html.

One of such priceless feature is the spaceless tag

{% spaceless %}
{{#Here goes your html#}}
{% endspaceless %}

Also you can use the syntax {{- name -}} to triming

{{-name }}




{{name- }}



and as you expected


will generate


This works for print statements {% … %} and comments {# … #}

Happy code optimization!