我们应该在使用 Thymeleaf 时删除 HTML 属性吗? [英] Should we remove HTML attributes while using Thymeleaf?

查看:27
本文介绍了我们应该在使用 Thymeleaf 时删除 HTML 属性吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究 Thymeleaf 并发现在几乎所有示例中都有 Thymeleaf 的标签值以及标准的 HTML 值,例如:

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>

这些标准标签值,如 Page Titlehref="../static/css/bootstrap-3.3.7-dist/bootstrap.min.css" 等. 被控制器忽略并且不在页面上呈现.

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.

推荐答案

这完全取决于您的开发过程.

This depends entirely on your development process.

您可以在早期阶段保留 HTML 属性,同时您仍在尝试仅使用浏览器来布置页面.

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.

但是,一旦您使用自动化单元/网络测试,您就可以安全地删除 HTML 属性,因为此测试应始终使用类似 prod 的环境(包括 thymeleaf).

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).

这篇关于我们应该在使用 Thymeleaf 时删除 HTML 属性吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆