Is it safe to omit and tags?

后端 未结 10 2088
广开言路
广开言路 2020-12-05 22:41

According to w3c and tags are optional, so the following table is perfectly valid.



        
      
      
      
10条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-05 23:12

    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.

提交回复
热议问题