application / x-javascript和text / javascript内容类型之间的区别 [英] Difference between application/x-javascript and text/javascript content types
问题描述
这些标题之间有什么区别?
What is the difference between these headers?
Content-Type: application/javascript
Content-Type: application/x-javascript
Content-Type: text/javascript
哪一个最好,为什么?
请不要说它们是相同的 - 如果它们相同则不会有两个相同。我知道两者都有效 - 但我想知道其中的区别。
Please do not say they are identical - if they were identical there would not have been two of them. I know both work - but I would like to know the difference.
推荐答案
text / javascript
已过时, application / x-javascript
是实验性的(因此 x -
前缀)可以标准化为 application / javascript
之前的过渡期。
text/javascript
is obsolete, and application/x-javascript
was experimental (hence the x-
prefix) for a transitional period until application/javascript
could be standardised.
您应该使用 application / javascript
。这是 RFC 。
就浏览器而言,那里没有区别(至少在HTTP标头中)。这只是一个更改,因此 text / *
和 application / *
MIME类型组在可能的情况下具有一致的含义。 ( text / *
MIME类型用于人类可读的内容,JavaScript不是为了直接向人类传达意义而设计的。)
As far a browsers are concerned, there is no difference (at least in HTTP headers). This was just a change so that the text/*
and application/*
MIME type groups had a consistent meaning where possible. (text/*
MIME types are intended for human readable content, JavaScript is not designed to directly convey meaning to humans).
请注意,在脚本元素的类型
属性中使用 application / javascript
将导致脚本被忽略(在一些旧版浏览器中使用未知语言)。要么继续使用 text / javascript
那么要么完全省略该属性(在HTML 5中允许)。
Note that using application/javascript
in the type
attribute of a script element will cause the script to be ignored (as being in an unknown language) in some older browsers. Either continue to use text/javascript
there or omit the attribute entirely (which is permitted in HTML 5).
这在HTTP标头中不是问题,因为浏览器普遍(据我所知)要么完全忽略HTTP内容类型的脚本,要么现代化足以识别 application / javascript
。
This isn't a problem in HTTP headers as browsers universally (as far as I'm aware) either ignore the HTTP content-type of scripts entirely, or are modern enough to recognise application/javascript
.
这篇关于application / x-javascript和text / javascript内容类型之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!