Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should we remove HTML attributes while using Thymeleaf?

Tags:

java

thymeleaf

I'm studying Thymeleaf and have found out that in almost all examples there are Thymeleaf's tag values as well as standard HTML values like:

<title th:text="#{product.page.title}">Page Title</title>

<link href="../static/css/bootstrap-3.3.7-dist/bootstrap.min.css" rel="stylesheet"
      th:href="@{/css/bootstrap-3.3.7-dist/bootstrap.css}"/>

<script src="../static/js/jquery-3.1.1.js"
        th:src="@{/js/jquery-3.1.1.js}"></script>

These standard tag values like Page Title or href="../static/css/bootstrap-3.3.7-dist/bootstrap.min.css" etc. are ignoring by controller and don't rendering on the page.

I'm wondering – is it just a good practice to leave them to improve code readability or it is better to remove them to clean up code?

Because for the compiler they are useless and have not any affect to the rendering result.

like image 407
DimaSan Avatar asked Sep 28 '16 21:09

DimaSan


People also ask

Why Thymeleaf is best suited to use in XHTML and html?

It is better suited for serving XHTML/HTML5 in web applications, but it can process any XML file, be it in web or in standalone applications. The main goal of Thymeleaf is to provide an elegant and well-formed way of creating templates.

How do I add another HTML to Thymeleaf?

Basic inclusion with th:insert and th:replace Thymeleaf can include parts of other pages as fragments (whereas JSP only includes complete pages) using th:insert (it will simply insert the specified fragment as the body of its host tag) or th:replace (will actually substitute the host tag by the fragment's).

What is the purpose of Thymeleaf?

Thymeleaf is a Java template engine for processing and creating HTML, XML, JavaScript, CSS and text.


1 Answers

This depends entirely on your development process.

You could keep the HTML attributes around in the early phases, while you are still trying to lay out the page using just your browser.

But, once you get to a point where you are using automated unit / web testing, you can safely remove the HTML attributes because this testing should always be using a prod-like environment (which would include thymeleaf).

like image 164
Jason Avatar answered Nov 04 '22 08:11

Jason