Difference between application/x-javascript and text/javascript content types(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
.
这篇关于application/x-javascript 和 text/javascript 内容类型之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:application/x-javascript 和 text/javascript 内容类型之间的区别
基础教程推荐
- 直接将值设置为滑块 2022-01-01
- 用于 Twitter 小部件宽度的 HTML/CSS 2022-01-01
- Electron 将 Node.js 和 Chromium 上下文结合起来意味着 2022-01-01
- html表格如何通过更改悬停边框来突出显示列? 2022-01-01
- 自定义 XMLHttpRequest.prototype.open 2022-01-01
- 如何使用JIT在顺风css中使用布局变体? 2022-01-01
- Chart.js 在线性图表上拖动点 2022-01-01
- 我可以在浏览器中与Babel一起使用ES模块,而不捆绑我的代码吗? 2022-01-01
- Vue 3 – <过渡>渲染不能动画的非元素根节点 2022-01-01
- 如何使用TypeScrip将固定承诺数组中的项设置为可选 2022-01-01