为 HTML 片段声明文档类型是否有意义?

Does it make sense to declare a doctype for an HTML fragment?

如果我有一个 HTML5 component/WebComponent,其中有一个 component.html 文件定义了一个 <template>,那么有一个 <!DOCTYPE html> 声明是否有意义在 component.html?也就是说,以下哪项是最佳做法?

<template>
    <!-- some html content -->
</template>

或者

<!DOCTYPE html>
<template>
    <!-- some html content -->
</template>

在所有支持 template 元素的现代浏览器中,两者都将以相同的方式进行解析和处理。

一个轻了几个八位!

所以这取决于您是否更喜欢速度而不是严格的标准合规性

遵循 KISS 原则:我编写(和阅读)的代码越少,我感觉越好 ;-)