Html 为什么 <META HTTP-EQUIV="Content-Script-Type" ...> 大多未使用?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6320084/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Why is <META HTTP-EQUIV="Content-Script-Type" ...> mostly unused?
提问by kay - SE is evil
Related:What's the point of Content-Script-Type and Content-Style-Type.
I wanted to know what the main reasons are that developers don't use
我想知道开发人员不使用的主要原因是什么
<meta http-equiv="content-script-type" content="text/javascript" />
and<meta http-equiv="content-style-type" content="text/css" />
<meta http-equiv="content-script-type" content="text/javascript" />
和<meta http-equiv="content-style-type" content="text/css" />
in their web projects. (Me neither, btw.)
在他们的网络项目中。(我也没有,顺便说一句。)
Saving one from having to declare the used type
on every instance of <script>
and <style>
, it does not seem to have any drawbacks. Yet, in fact, I have never seen one of them in the wild. Are there any considerations one has to take when relying on these <meta>
tags?
免于必须type
在<script>
and 的每个实例上声明 used <style>
,它似乎没有任何缺点。然而,事实上,我从未在野外见过其中一只。依赖这些<meta>
标签时是否需要考虑任何因素?
回答by vulcan raven
According to W3C, http-equiv values "content-style-type" & "content-script-type" attributes are unknown
for HTML5 meta markup! Moreover, W3C validator throws the following error when an HTML5 page has such markups:
根据W3C,http-equiv 值“content-style-type”和“content-script-type”属性unknown
用于 HTML5 元标记!此外,当 HTML5 页面具有此类标记时,W3C 验证器会引发以下错误:
Line X, Column Y: Bad value Content-Script-Type for attribute http-equiv on element meta.
<meta http-equiv="Content-Script-Type" content="text/javascript">
X 行,Y 列:元素元上的 http-equiv 属性值内容脚本类型错误。
<meta http-equiv="Content-Script-Type" content="text/javascript">
So essentially we are supposed to avoid them.
所以基本上我们应该避免它们。
回答by duskwuff -inactive-
All web browsers that I've heard of will default to assuming type="text/javascript"
on all <script>
tags, and type="text/css"
on <style>
tags. (The only meaningful alternative I've heard of is VBScript for <script>
tags in MSIE, which is heavily deprecated. There's no alternative to CSS.) In recognition of this, the HTML5 spec defines both attributes as being newly optional.
我听说过的所有网页浏览器将默认为假定type="text/javascript"
所有的<script>
标签,并type="text/css"
在<style>
标签。(我听说过的唯一有意义的替代方案是<script>
MSIE 中用于标记的VBScript ,它已被严重弃用。CSS 没有替代方案。)认识到这一点,HTML5 规范将这两个属性定义为新的可选属性。
As such, there's no point in the Content-Script-Type
and Content-Style-Type
meta tags -- as far as I'm aware, they're ignored by most, if not all, browsers.
因此,元标记Content-Script-Type
和Content-Style-Type
元标记没有意义——据我所知,它们被大多数(如果不是全部)浏览器忽略。
回答by Daniel Rhodes
It's a shame that these settings have become deprecated with HTML5. Because, as nobody else seems to be mentioning, you can put default character set settings in there as well! Thus:
遗憾的是,这些设置已被 HTML5 弃用。因为,正如其他人似乎没有提到的那样,您也可以在其中放置默认字符集设置!因此:
<meta http-equiv="Content-Script-Type" content="text/javascript; charset=UTF-8;">
<meta http-equiv="Content-Style-Type" content="text/css; charset=UTF-8;">
<meta http-equiv="Content-Script-Type" content="text/javascript; charset=UTF-8;">
<meta http-equiv="Content-Style-Type" content="text/css; charset=UTF-8;">
回答by Albert
<meta http-equiv="Content-Style-Type" content="text/css; charset=UTF-8;">
The CSS meta is important for inline styles where we can't declare the type, so:
CSS 元对于无法声明类型的内联样式很重要,因此:
<span style="background:pink">
回答by harpo
Speaking as a developer who just learned about these tags from your question, I'd say that it's the curse of the legacy browsers (I'm looking at you, IE6). Because when I learn about new tags, I usually continue not using them. I always assume browsers mightnot support any feature that I've never heard of, until I prove otherwise (which takes time), and since you have to program to the least common denominator (even if you "progressively enhance" later), that means, in this case, using the safer, more verbose method.
作为刚刚从您的问题中了解这些标签的开发人员,我会说这是旧浏览器的诅咒(我正在看着您,IE6)。因为当我了解新标签时,我通常会继续不使用它们。我总是假设浏览器可能不支持我从未听说过的任何功能,除非我证明不然(这需要时间),并且由于您必须对最小公分母进行编程(即使您以后“逐步增强”),那在这种情况下,意味着使用更安全、更详细的方法。
Having said that, I may actually give these a try. There's little risk, unless you're using content types other thantext/javascript
and text/css
, since those have been the assumed defaults, like, forever. Indeed, as @duskwuff points out, there's probably no point in using either.
话虽如此,我实际上可以尝试一下。除非您使用and以外的内容类型,否则风险很小,因为它们一直是假定的默认值,例如永远。事实上,正如@duskwuff 指出的那样,使用两者可能都没有意义。text/javascript
text/css
回答by icarter
Being HTTP-EQUIV - this has little to do with being deprecated in HTML5 (because here indeed the defaults are JS and CSS - which also makes the type-attribute unnecessary) - there is still the HTTP protocol: https://www.ietf.org/rfc/rfc4229.txt#2.1.30
作为 HTTP-EQUIV - 这与在 HTML5 中被弃用几乎没有关系(因为这里确实默认是 JS 和 CSS - 这也使得类型属性变得不必要) - 还有 HTTP 协议:https://www.ietf .org/rfc/rfc4229.txt#2.1.30
so you can from the serverside very well send HTTP headers e.g. from PHP
所以你可以从服务器端很好地发送 HTTP 标头,例如从 PHP
<?php
header('Content-Type: text/html; charset=UTF-8');
header('Content-Script-Type: text/javascript');
header('Content-Style-Type: text/css');
or node
或节点
res.set('Content-Type', 'text/html; charset=UTF-8');
res.set('Content-Script-Type', 'text/javascript');
res.set('Content-Style-Type', 'text/css');
回答by Jason
They are depreciated. Now, people use <script type='text/javascript>
and <style type='text/css'>
.
它们折旧了。现在,人们使用<script type='text/javascript>
和<style type='text/css'>
。
回答by Francois Rossello
<script type="text/javascript">
is depricated, so use
被贬低,所以使用
<script type="application/javascript">
instead like mentioned here in april 2006. Start hereto find the last content.