text / javascript和application / javascript之间有什么区别 [英] what is difference between text/javascript and application/javascript

查看:84
本文介绍了text / javascript和application / javascript之间有什么区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

在提供JavaScript文件时,使用应用程序/ javascript或application / x-javascript更好


text / javascript和application / javascript有什么区别?



如果你已经将类型属性设置为application / javascript,那么IE将完全忽略脚本标记。



但主要区别是什么,在这种情况下我们需要使用特定的。

解决方案

文字/ javascript是在网络年轻时引入的,人们还没有想过。



然后人们考虑了事情,并决定将text / *保留用于人类可读的东西(这就是为什么有些XML是text / xml和其他XML是appli阳离子/ XML)。 JavaScript不是人类可读的,因此不推荐使用text / javascript并引入application / javascript来替换它。



多年以后,一些浏览器仍然没有赶上。 / p>

您可以将服务器配置为始终在HTTP标头中提供application / javascript;不支持它的浏览器也不关注实际的内容类型。



目前,如果您正在编写HTML 4或XHTML 1,请指定文本为了向后兼容性,在type属性中使用/ javascript。如果您正在编写HTML 5,则省略type属性(因为它现在是可选的)。


Possible Duplicate:
When serving JavaScript files, is it better to use the application/javascript or application/x-javascript

what is difference between text/javascript and application/javascript?

As IE will completely ignore the script tag if you have set type attribute to application/javascript.

But what is the main difference and in which case we need to use the particular.

解决方案

text/javascript was introduced when the web was young and people hadn't thought things through.

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.

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.

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).

这篇关于text / javascript和application / javascript之间有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆