text / javascript vs application / javascript [英] text/javascript vs application/javascript

查看:122
本文介绍了text / javascript vs application / javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很好奇MIME类型 application / javascript text / javascript 的语义。

I am curious about the semantics of the MIME types application/javascript versus text/javascript.

显然,一个应该被执行,而另一个应该只是文本。

Obviously, one is supposed to be executed, and the other is supposed to be just text.

在查看外部.js加载的标题时,我看到 application / javascript

I see application/javascript when looking at headers of an external .js load.

HTTP/1.1 200 OK
Date: Mon, 13 Jan 2014 18:32:58 GMT
Server: Apache/2.2.22 (Unix) mod_ssl/2.2.22 OpenSSL/0.9.8e-fips-rhel5
Content-Type: application/javascript
Content-Length: 856
keep-alive: timeout=5, max=59
Via: 1.1 (jetty)
Accept-Ranges: bytes

如果这个 application / javascript 将执行javascript,为什么我们不使用

If this application/javascript will execute the javascript, why don't we use

<script type="application/javascript">
  // some js code.
</script>

反之亦然,为什么外部js加载不是 text / javascript

And vice-versa, why is an external js load not text/javascript?

推荐答案

按此 text / javascript 已过时。请改用 application / javascript


text / javascript(已废弃):JavaScript;在RFC 4329中定义并过时
,以阻止其使用,支持
application / javascript。但是,HTML 4
和5中允许使用text / javascript,与application / javascript不同,它具有跨浏览器支持。
HTML5中标签的type属性是可选的,
根本不需要使用它,因为所有浏览器总是假定
是正确的默认值(即使在HTML 4中它也是如此)需要
规范)。

text/javascript (Obsolete): JavaScript; Defined in and made obsolete in RFC 4329 in order to discourage its usage in favor of application/javascript. However, text/javascript is allowed in HTML 4 and 5 and, unlike application/javascript, has cross-browser support. The "type" attribute of the tag in HTML5 is optional and there is no need to use it at all since all browsers have always assumed the correct default (even in HTML 4 where it was required by the specification).

此标准与IE< = 8不兼容。

这篇关于text / javascript vs application / javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆