为什么在服务器设置mime类型时写?

前端之家收集整理的这篇文章主要介绍了为什么在服务器设置mime类型时写?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我的理解是mime类型是由web服务器设置的。为什么我们添加type =“text / javascript或type =”text / css“属性?这不是一个无用的和被忽略的属性

解决方法

Douglas Crockford says

type="text/javascript"

This attribute is optional. Since
Netscape 2,the default programming
language in all browsers has been
JavaScript. In XHTML,this attribute
is required and unnecessary. In HTML,
it is better to leave it out. The
browser knows what to do.

He also says:

W3C did not adopt the language
attribute,favoring instead a type
attribute which takes a MIME type.
Unfortunately,the MIME type was not
standardized,so it is sometimes
"text/javascript" or
"application/ecmascript" or something
else. Fortunately,all browsers will
always choose JavaScript as the
default programming language,so it is
always best to simply write <script>.
It is smallest,and it works on the
most browsers.

仅为娱乐目的,我试用了以下五个脚本

<script type="application/ecmascript">alert("1");</script>
  <script type="text/javascript">alert("2");</script>
  <script type="baloney">alert("3");</script>
  <script type="">alert("4");</script>
  <script >alert("5");</script>

在Chrome上,所有脚本3(type =“baloney”)都工作。 IE8没有运行脚本1(type =“application / ecmascript”)或脚本3.基于我的两个浏览器的非广泛的示例,它看起来像你可以安全地忽略type属性,但它使用它你最好使用一个法律(依赖浏览器)值。

原文链接:https://www.f2er.com/css/222699.html

猜你在找的CSS相关文章