Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
308 views
in Technique[技术] by (71.8m points)

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

Which one is best and why?

(哪一个最好,为什么?)

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.

(我知道两者都有效 - 但我想知道其中的区别。)

  ask by Obmerk Kronen translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

text/javascript is obsolete, and application/x-javascript was experimental (hence the x- prefix) for a transitional period until application/javascript could be standardised.

(text/javascript已经过时, application/x-javascript是实验性的(因此是x-前缀),用于过渡期,直到application/javascript可以标准化。)

You should use application/javascript .

(你应该使用application/javascript)

This is documented in the RFC .

(这在RFC中有记录 。)

As far a browsers are concerned, there is no difference (at least in HTTP headers).

(就浏览器而言,没有区别(至少在HTTP标头中)。)

This was just a change so that the text/* and application/* MIME type groups had a consistent meaning where possible.

(这只是一个更改,因此text/*application/* MIME类型组在可能的情况下具有一致的含义。)

( text/* MIME types are intended for human readable content, JavaScript is not designed to directly convey meaning to humans).

(( text/* MIME类型用于人类可读的内容,JavaScript不是为了直接向人类传达意义)。)

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.

(请注意,在脚本元素的type属性中使用application/javascript将导致在某些旧版浏览器中忽略脚本(如未知语言)。)

Either continue to use text/javascript there or omit the attribute entirely (which is permitted in HTML 5).

(继续在那里使用text/javascript或完全省略该属性(这在HTML 5中是允许的)。)

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 .

(这在HTTP标头中不是问题,因为普遍使用的浏览器(据我所知)要么完全忽略脚本的HTTP内容类型,要么现代化足以识别application/javascript 。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...