Possible Duplicate:
When serving JavaScript files, is it better to use the application/javascript or application/x-javascript可能重复:在提供JavaScript文件时,使用application / javascript或application / x-javascript是否更好
what is difference between text/javascript and application/javascript?
text / javascript和application / javascript有什么区别?
As IE will completely ignore the script tag if you have set type attribute to application/javascript.
如果您已将type属性设置为application / javascript,则IE将完全忽略脚本标记。
But what is the main difference and in which case we need to use the particular.
但主要区别是什么,在这种情况下我们需要使用特定的。
2 个解决方案
#1
47
text/javascript was introduced when the web was young and people hadn't thought things through.
text / javascript是在网络年轻时推出的,人们还没有想到。
Then people thought things through, and decided that text/* should be reserved for things designed to be human readable (which is why some XML is text/xml and other XML is application/xml). JavaScript is not human readable, so text/javascript was deprecated and application/javascript was introduced to replace it.
然后人们仔细思考,并决定将text / *保留给人类可读的东西(这就是为什么有些XML是text / xml而其他XML是application / xml)。 JavaScript不是人类可读的,因此不推荐使用text / javascript,并引入了application / javascript来替换它。
Years later, some browsers still haven't caught up.
多年以后,一些浏览器仍未赶上。
You can configure your server to always serve application/javascript in the HTTP headers; browsers that don't support it also pay no attention to the actual content-type.
您可以将服务器配置为始终在HTTP标头中提供application / javascript;不支持它的浏览器也不关注实际的内容类型。
For the time being, if you are writing HTML 4 or XHTML 1, specify text/javascript in the type attribute for the sake of backwards compatibility. If you are writing HTML 5, then omit the type attribute (as it is now optional).
目前,如果您正在编写HTML 4或XHTML 1,请在type属性中指定text / javascript以便向后兼容。如果您正在编写HTML 5,则省略type属性(因为它现在是可选的)。
#2
6
HTML 4.01 (1999) specification suggests using MIME type text/javascript
(http://www.w3.org/TR/1999/REC-html401-19991224/interact/scripts.html#h-18.2.2.2).
HTML 4.01(1999)规范建议使用MIME类型text / javascript(http://www.w3.org/TR/1999/REC-html401-19991224/interact/scripts.html#h-18.2.2.2)。
However, RFC 4329 (2006) now recommends the use of application/javascript
.
但是,RFC 4329(2006)现在建议使用application / javascript。
It seems that historically text/javascript
was used a lot and since it was the type that browsers most likely supported, this was the type that got suggested also in the HTML specification. Ideally, you would use application/javascript
.
似乎历史上文本/ javascript被大量使用,因为它是浏览器最可能支持的类型,这也是HTML规范中提出的类型。理想情况下,您将使用application / javascript。
In practice you may need to use text/javascript
to provide compatibility with less-conforming browsers.
在实践中,您可能需要使用text / javascript来提供与不太符合要求的浏览器的兼容性。
#1
47
text/javascript was introduced when the web was young and people hadn't thought things through.
text / javascript是在网络年轻时推出的,人们还没有想到。
Then people thought things through, and decided that text/* should be reserved for things designed to be human readable (which is why some XML is text/xml and other XML is application/xml). JavaScript is not human readable, so text/javascript was deprecated and application/javascript was introduced to replace it.
然后人们仔细思考,并决定将text / *保留给人类可读的东西(这就是为什么有些XML是text / xml而其他XML是application / xml)。 JavaScript不是人类可读的,因此不推荐使用text / javascript,并引入了application / javascript来替换它。
Years later, some browsers still haven't caught up.
多年以后,一些浏览器仍未赶上。
You can configure your server to always serve application/javascript in the HTTP headers; browsers that don't support it also pay no attention to the actual content-type.
您可以将服务器配置为始终在HTTP标头中提供application / javascript;不支持它的浏览器也不关注实际的内容类型。
For the time being, if you are writing HTML 4 or XHTML 1, specify text/javascript in the type attribute for the sake of backwards compatibility. If you are writing HTML 5, then omit the type attribute (as it is now optional).
目前,如果您正在编写HTML 4或XHTML 1,请在type属性中指定text / javascript以便向后兼容。如果您正在编写HTML 5,则省略type属性(因为它现在是可选的)。
#2
6
HTML 4.01 (1999) specification suggests using MIME type text/javascript
(http://www.w3.org/TR/1999/REC-html401-19991224/interact/scripts.html#h-18.2.2.2).
HTML 4.01(1999)规范建议使用MIME类型text / javascript(http://www.w3.org/TR/1999/REC-html401-19991224/interact/scripts.html#h-18.2.2.2)。
However, RFC 4329 (2006) now recommends the use of application/javascript
.
但是,RFC 4329(2006)现在建议使用application / javascript。
It seems that historically text/javascript
was used a lot and since it was the type that browsers most likely supported, this was the type that got suggested also in the HTML specification. Ideally, you would use application/javascript
.
似乎历史上文本/ javascript被大量使用,因为它是浏览器最可能支持的类型,这也是HTML规范中提出的类型。理想情况下,您将使用application / javascript。
In practice you may need to use text/javascript
to provide compatibility with less-conforming browsers.
在实践中,您可能需要使用text / javascript来提供与不太符合要求的浏览器的兼容性。