我应该包括type =" text / javascript"在我的SCRIPT标签中? [英] Should I include type="text/javascript" in my SCRIPT tags?

查看:201
本文介绍了我应该包括type =" text / javascript"在我的SCRIPT标签中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过 Crockford的JavaScript最佳实践阅读,他说:


无需使用语言或类型属性。确定MIME类型的是服务器,而不是脚本标记。

There is no need to use the language or type attributes. It is the server, not the script tag, that determines the MIME type.

但我从未见过有人省略< script> 标记中输入属性...

But I've never seen anyone omit the type attribute in their <script> tag...

你们包括类型吗?为什么(不是)?

Do you guys include type? Why (not)?

推荐答案

你误解了Crockford的意思,他没有说类型属性完全无效,只是它不正确。 JavaScript的MIME类型是 application / javascript (或 application / ecmascript 我现在不记得了。)

You misunderstood what Crockford meant, he didn't say the type attribute is completely invalid, it's just that it's incorrect. The MIME type for JavaScript is application/javascript (or application/ecmascript I can't remember right now).

一般用法是 text / javascript 哪些浏览器会处理没有任何问题,因为那是 defacto 标准很长一段时间。

The general usage though is that is text/javascript which browsers will handle without any problems as that's been the defacto standard for a long time.

关于< script src =...标记它是多余的,因为服务器确定文件的MIME类型,然后浏览器将处理该文件。

In regards to the <script src="..." tag it is redundant because the server determines the MIME type of the file and that is what the browser will then deal with.

他最好在一个文件中解释它他在YUI剧院的视频( http://developer.yahoo.com/yui/theater/)。我不记得究竟是哪一个谈论这个,我认为它是在高级JavaScript系列中(但是我已经看了几遍,所以它们彼此模糊不清)。

He best explains it in one of his videos on YUI Theater (http://developer.yahoo.com/yui/theater/). I don't remember exactly which one he talks about this, I think it was in the advanced JavaScript series (but yeah I've watched them all a few times so they kind of blur into each other).

因此,如果您想编写有效的XHTML,您需要提供类似 text / javascript 的内容,但这不是官方 JavaScript语言的MIME类型。

So if you want to write valid XHTML you need to provide something like text/javascript but it's not the official MIME type of the JavaScript language.

这篇关于我应该包括type =&quot; text / javascript&quot;在我的SCRIPT标签中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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