Why is <META HTTP-EQUIV=“Content-Script-Type” …> mostly unused?

梦想的初衷 提交于 2019-11-28 21:11:46

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:

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">

So essentially we are supposed to avoid them.

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.

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.

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:

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

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 might not 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.

Having said that, I may actually give these a try. There's little risk, unless you're using content types other than text/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.

<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:

<span style="background:pink">

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

so you can from the serverside very well send HTTP headers e.g. from 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');

They are depreciated. Now, people use <script type='text/javascript> and <style type='text/css'>.

Francois Rossello
<script type="text/javascript">

is depricated, so use

<script type="application/javascript">

instead like mentioned here in april 2006. Start here to find the last content.

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