What's the point of Content-Script-Type and Content-Style-Type

ⅰ亾dé卋堺 提交于 2019-12-04 23:30:52

问题


Consider these two lines:

<meta http-equiv="Content-Script-Type" content="text/javascript" />
<meta http-equiv="Content-Style-Type" content="text/css" />

From the W3's documentation on Scripting, in the section The default scripting language:

Authors should specify the default scripting language for all scripts in a document by including the following META declaration in the HEAD

Yet it continues in Local declaration of a scripting language to say:

The type attribute must be specified for each SCRIPT element instance in a document. The value of the type attribute for a SCRIPT element overrides the default scripting language for that element.

Seems to me like there's an over-specification here. Why are both the meta and per-script type declarations required? What's the point of a mandatory default if we 'must' declare each tag individually anyway?

Either let the default be the default, or just state that each tag needs it's own type - or is the wording here just getting me tripped up? The same language is used with reference to style sheets as well.


回答1:


The <script> and <style> elements are only one way of adding scripting and styling to HTML.

For scripting, we have event handler attributes, for styling HTML 4.01 defines the <link> element, the Link: HTTP header and the "style" attribute. In each of these cases, specifying the language is not mandated, so the fall-back would be the value of Content-Script-Type and Content-Style-Type.

For example: the scripting section says:

Documents that do not specify default scripting language information and that contain elements that specify an intrinsic event script are incorrect. User agents may still attempt to interpret incorrectly specified scripts but are not required to. Authoring tools should generate default scripting language information to help authors avoid creating incorrect documents.

and the styling section has an equivalent statement:

Documents that include elements that set the style attribute but which don't define a default style sheet language are incorrect. Authoring tools should generate default style sheet language information (typically a META declaration) so that user agents do not have to rely on a default of "text/css".

Note that these requirements are not DTD expressable, so validators that rely on a DTD won't flag violations as errors.

Whether any browser actually pays any attention to the settings, I've no idea.



来源:https://stackoverflow.com/questions/6268181/whats-the-point-of-content-script-type-and-content-style-type

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!