脚本标记的type属性的javascript MIME类型是什么?

时间:2008-10-10 01:48:41

标签: javascript mime-types

MIME类型的javascript是什么?

更具体地说,在脚本标记的“type”属性中放入什么是正确的? application/x-javascripttext/javascript似乎是主要竞争者。

5 个答案:

答案 0 :(得分:134)

这是一个常见的错误。 javascript的MIME类型多年未标准化。它现在是officially:“ application / javascript ”。

这里真正的踢球者是大多数浏览器无论如何都不会使用该属性,至少在脚本标记的情况下不会。他们实际上偷看了数据包并确定了自己的类型。

所以最重要的是,就javascript而言,type =“text / javascript”没有做任何事情,但它是 HTML 4 XHTML 1.0 。

答案 1 :(得分:21)

这是我在这个主题上发现的第一页,对此有任何意义。

我的集体研究表明:

  1. text/javascript正如Keparo所述,如果您想要验证,必须在html4和xhtml1中使用。虽然浏览器会忽略它。
  2. application/javascript如果每个人都同意并且当一切都赶上时,应该是新的官方MIME类型。
  3. application/x-javascript(x表示非正式)是javascript的当前服务器端MIME引用。
  4. 每个人都希望,按照惯例,微软将决定做一些完全不同的事情,以进一步混淆和填补此事。
  5. 摘要:目前,如果您希望html / xhtml在MSIE中工作并使用W3C进行验证,则声明type="text/javascript"。如果您希望您的网络服务器知道您的意思是javascript,请使用application/x-javascript

答案 2 :(得分:4)

文本/ JavaScript的

我相信IE不接受application / x-javascript

Specifying the scripting language

答案 3 :(得分:2)

在脚本标签中我会使用text / javascript。无论如何,这都出现在HTML 4.0规范中。

http://www.w3.org/TR/REC-html40/interact/scripts.html

[编辑]有趣的是,应用程序/ javascript标准化的RFC是2年,但文本/ javascript仍然更常见。这是另一个定制胜过标准的案例吗?它也出现在HTML5

答案 4 :(得分:1)

定义Javascript MIME类型的官方RFC是RFC4329

     
7.  JavaScript Media Types

7.1.  text/javascript (obsolete)

   Type name:               text
   Subtype name:            javascript
   Required parameters:     none
   Optional parameters:     charset, see section 4.1.
   Encoding considerations:
      The same as the considerations in section 3.1 of [RFC3023].

   Security considerations: See section 5.
   Interoperability considerations:
      None, except as noted in other sections of this document.

   Published specification: [JS15]
   Applications which use this media type:
      Script interpreters as discussed in this document.

   Additional information:

      Magic number(s):             n/a
      File extension(s):           .js
      Macintosh File Type Code(s): TEXT

   Person & email address to contact for further information:
      See Author's Address section.

   Intended usage:          OBSOLETE
   Restrictions on usage:   n/a
   Author:                  See Author's Address section.
   Change controller:       The IESG.

7.2.  application/javascript

   Type name:               application
   Subtype name:            javascript
   Required parameters:     none
   Optional parameters:     charset, see section 4.1.
   Encoding considerations:
      The same as the considerations in section 3.2 of [RFC3023].

   Security considerations: See section 5.
   Interoperability considerations:
      None, except as noted in other sections of this document.

   Published specification: [JS15]
   Applications which use this media type:
      Script interpreters as discussed in this document.

   Additional information:

      Magic number(s):             n/a
      File extension(s):           .js
      Macintosh File Type Code(s): TEXT

   Person & email address to contact for further information:
      See Author's Address section.

   Intended usage:          COMMON
   Restrictions on usage:   n/a
   Author:                  See Author's Address section.
   Change controller:       The IESG.