刚才我发了一篇 《那些前端程序员深信不疑的谣言( HTML 篇)》科普文,有人说我不懂团队规范,这些符号怎么能省呢?
那我来跟你扯一扯团队规范。
Google Style Guide 关于 HTML/CSS 的 Style Guide :
For file size optimization and scannability purposes, consider omitting optional tags. The HTML5 specification defines what tags can be omitted.
(This approach may require a grace period to be established as a wider guideline as it ’ s significantly different from what web developers are typically taught. For consistency and simplicity reasons it ’ s best served omitting all optional tags, not just a selection.)
<!-- Not recommended -->
<!DOCTYPE html>
<html>
<head>
<title>Spending money, spending bytes</title>
</head>
<body>
<p>Sic.</p>
</body>
</html>
<!-- Recommended -->
<!DOCTYPE html>
<title>Saving money, saving bytes</title>
<p>Qed.
- html/head/body 标签写了么?
- p 标签闭合了吗?
注意这个团队规范有点激进,目前是 optional ,还在兼容 IE 的团队测试后再采用。
关于 <br /> 的Style Guide
Although fine with HTML, do not close void elements, i.e. write <br>, not <br />.
以上。