application/x-javascript 和 text/javascript 内容类型之间的区别
这些标头有什么区别?
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 three 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).
请注意,在脚本元素的 type
属性中使用 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
.
相关文章