可选的关闭HTML标签(例如& lt;/TR& gt;)是否会给浏览器的HTML解析器带来额外的费用? [英] Do optional closing HTML tags (e.g. </TR>) present extra cost to browser's HTML parser?

查看:41
本文介绍了可选的关闭HTML标签(例如& lt;/TR& gt;)是否会给浏览器的HTML解析器带来额外的费用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据最近的问题,HTML4标准表示关闭</TD> /</TR> 标签是可选的.

As per this recent question, HTML 4 standard indicates that closing </TD>/</TR> tags are optional.

问题是,如果您编写HTML时省略了那些结束标记,这会影响浏览器的HTML解析器必须以一种或另一种方式完成的工作量吗?

The question is, if you write your HTML omitting those closing tags, would that affect the amount of work that the browser's HTML parser must do one way or the other?

我意识到,即使有任何效果,差异也可能很小,在实践中并不重要-这个问题纯粹出于理论上的好奇心.

I realize that the difference - even if there's any effect - would probably be minuscule and not matter in practice - this question is out of pure theoretical curiosity.

我自己的想法是,从要解析的文本较少的文本中获益不多,并且没有损失,因为应该有一个代码可以解析TD或TR中的开始标签,即使它们的结束标签不是不是可选的;因此,使其成为可选代码的唯一成本是检查< TD> 中包含的打开标记是另一个< TD> 还是< TR> 没有以前遇到的嵌套< TABLE> ...似乎不是很昂贵的添加.

My own thinking is that there will be a modest gain, from having less text to parse, and no loss, since there ought to be a code for parsing an opening tag inside a TD or TR anyway even if their closing tags weren't optional; and therefore the only cost code-wise for making them optional is a check whether an open tag contained in <TD> is another <TD> or <TR> without a previously encountered nested <TABLE>... doesn't seem like a very costly addition.

推荐答案

我创建了一个带有疯狂大表的裸HTML页面:100,000个单元散布在1000列和100行中,每个单元都填充有"x".有效的XHTML大小约为10MB,有效的HTML大小约为5MB.我在FF 3.6.11和IE8上的3次运行中对其进行了测试.浏览器在每次运行时都会干净启动.

I created a bare HTML page with with an insane large table: 100,000 cells spread over 1000 columns and 100 rows, each filled with "x". The XHTML-valid one is about 10MB in size and the HTML-valid one is about 5MB in size. I tested it in 3 runs on FF 3.6.11 and IE8. Browsers are started clean on every run.

FF有效的XHTML有效时间平均为2分5秒,而HTML有效的时间平均花费1分15秒.

FF took on average 2 minutes and 5 seconds for the XHTML valid one and 1 minute and 15 seconds for the HTML valid one.

对于XHTML有效版本,IE8平均花费1分40秒,而对HTML有效时间花费相同的时间.但是,在所有情况下,它的结尾都是空白页.

IE8 took on average 1 minute and 40 seconds for the XHTML valid one and the same time for the HTML valid one. It however ends up with a blank page on all occurrences.

以上结果可供进一步解释.对我来说,我比网络浏览器的功能更担心网络带宽和可维护性.网络带宽的成本更高.

Above results are open for further interpretation. To me, I would worry more about network bandwidth and maintainability than about browser's capabilities. Network bandwidth costs more $$$.

这篇关于可选的关闭HTML标签(例如&amp; lt;/TR&amp; gt;)是否会给浏览器的HTML解析器带来额外的费用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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