Removing whitespace in the generated HTML

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Removing whitespace in the generated HTML

Novabyte
I looked through the Thymeleaf 2.0 documentation and I wasn't able to find an option to render the template output without whitespace. I'd like to reduce the filesize of the rendered HTML by stripping the whitespace.

For more information see this: https://developer.mozilla.org/en/HTML/Tips_for_authoring_fast-loading_HTML_pages#Reduce_page_weight

Is this possible?

Thanks in advance.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Removing whitespace in the generated HTML

danielfernandez
Administrator
The standard configuration does not do this, but you can create your own "writer" (implementation of ITemplateWriter) and then register your own template mode that uses it (ITemplateModeHandler, see the "Template Modes" section at the "Extending Thymeleaf" guide).

Having your own template mode will allow you to precisely define the way your results should be written back to HTML.

Have a look at the existing implementations at org.thymeleaf.templatewriter. You can probably use one of the existing implementations as a base.

Also, don't hesitate adding a feature request at our issue management system.

Regards,
Daniel
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Removing whitespace in the generated HTML

Novabyte
Thanks for the response. I will submit a feature request to the project, I think this is a useful addition, it complements the "Web 2.0" obsession with reducing KB down the wire.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Removing whitespace in the generated HTML

NoSuchLuke
I was looking for this feature too.

But one nice thing already (compared to, say, classic JSP) is that a neatly formatted source yields a neatly formatted output, since Thymeleaf works via attributes, rather than elements that can drag in extra newlines and such.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Removing whitespace in the generated HTML

anil1712
Hey, I found this link for same issyue https://github.com/thymeleaf/thymeleaf/issues/108.
Have anyone checked it? or there are some other solution for the same, actually I need Java Based configuration and the provided links has XML configuration. Please give me some solution for this.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Removing whitespace in the generated HTML

Cesarvv
In reply to this post by Novabyte
Hola, estoy usando thymeleaf 3.0 y a mí también me genera espacios en blanco, pero lo solucioné usando el codigo así:

<th:block th:fragment="menu"><div id="menu">
...

en vez de así:

<th:block th:fragment="menu">
<div id="menu">
...

en la primera línea hay que colocarlo seguido, y desaparece los espacios en blanco.

Loading...