省略< / TD>是否安全?和< / TR>标签? [英] Is it safe to omit </TD> and </TR> tags?

查看:85
本文介绍了省略< / TD>是否安全?和< / TR>标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据 w3c < / TD> ; < / TR> 标签是可选的,所以下表非常有效。

 < table> 
< tr>
< td> google
< td> chrome
< / table>

我用测试过的所有浏览器渲染表格。我只是想问,这是否通常被认为可以安全使用,或者如果我无法访问的旧浏览器导致问题。谢谢。



它可以将含有许多表格的页面上的gzip html大小减少百分之几。

方法

这是安全的,因为标准中的选择性意味着所有的浏览器(至少是那些甚至是远程问题的浏览器)都会实现这一点 - 而浏览器标准的遵从性通常运行到另一端,试图与甚至无效的HTML正确工作,而不是失踪的可选标签。



说到这一点,我发现省略这样的标签会使事情更难以阅读,这可能或者如果目标是尺寸优化,可能无关紧要。



PS另外,如果你有非常大的表格,我想知道在处理这样的结构时浏览器的HTML解析器是否会产生任何开销?我不确定没有对HTML解析器如何工作的基准或真正深入的思考,但如果它发生,它可能是一个因素。


According to w3c </TD> and </TR> tags are optional, so the following table is perfectly valid.

<table>
  <tr>
    <td>google
    <td>chrome
</table>

And all browsers I've tested it with render the table fine. I just wanted to ask if this is generally considered safe to use, or if older browsers, which I don't have access to, cause problems. Thanks.

It reduces gzip html size on a page with many tables by a few percent.

解决方案

It is safe, since optionality in the standard means that all the browsers (at least the ones which even remotely matter) would have implemented this - and the browser standards compliance usually runs to the opposite side, into trying to work correctly with even invalid HTML as opposed to failing on missing optional tags.

Having said that, I find that omitting such tags makes things harder to read, which may or may not matter to you if the goal is size optimization.

P.S. Also, if you have very large tables, I wonder whether there's any overhead incurred by the browser's HTML parser when dealing with such constructs? I am not sure without benchmarking or really deep thinking about how HTML parser works in detail, but it is something that could possibly be a factor if it happens.

这篇关于省略&lt; / TD&gt;是否安全?和&lt; / TR&gt;标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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