Paul Croarkin
Paul Croarkin

Reputation: 14675

Thymeleaf Double Reference to CSS

In many Thymeleaf examples (such as a Spring Boot Thymeleaf example, links to stylesheets are referenced twice in the link where the first reference uses the Thymeleaf th:ref and the second uses a standard href:

<link rel="stylesheet"
    th:href="@/css/bootstrap.min.css}"
    href="../../css/bootstrap.min.css"
 />

Removing the href="../../css/bootstrap.min.css" does not seem to break anything.

Is there any benefit to having the double reference or could something go wrong if the second reference is removed?

Upvotes: 1

Views: 121

Answers (1)

Leandro Carracedo
Leandro Carracedo

Reputation: 7345

There is no need for the second href as explained in the documentation:

The th:href tag allowed us to (optionally) have a working static href attribute in our template, so that our template links remained navigable by a browser when opened directly for prototyping purposes.

So the benefit of having the static reference is to have a working template and navigable using a browser, the best case for prototyping. But if you want to remove it, nothing goes wrong.

Upvotes: 1

Related Questions