什么是的 MIME 类型的javascript?

更具体而言,什么是正确的事情放在"类型"属性的一个脚本标签? application/x-javascripttext/javascript 似乎是主要竞争者。

有帮助吗?

解决方案

这是一种常见的错误。MIME type javascript不是标准化的多年。它是现在 正式: "应用/javascript".

真正的喷射器在这里的是,大多数浏览器不会使用,即属性无论如何,至少不在的情况的剧本标记。他们实际上偷看里面包和类型确定为他们自己。

因此,底线是,type="text/javascript"不做任何事情尽javascript感到关切的是,但这是部分的规格为 HTML4XHTML1.0.

其他提示

远出这是第一页上我发现对该主题与任何意义。

我的集体研究建议:

  1. text/javascript 作为Keparo指出,必须使用在html4和xhtml1如果你想要验证。虽然浏览器忽略它。
  2. application/javascript 预计新的官方MIME type如果每个人都同意,当一切都抓了起来。
  3. application/x-javascript (x意义非官方的)是目前的服务器侧MIME参考javascript。
  4. 每个人都希望,如往常一样,微软将决定做一些完全不同的东西,进一步混淆和材料的问题。

摘要:现在,如果你想要你html/xhtml工作MSIE和验证W3C然后宣布 type="text/javascript".如果你想要你的网服务器以知道你的意思是javascript然后使用 application/x-javascript.

文/javascript

我相信,即不接受application/x-javascript

指定的脚本语言

在一个脚本标记我会用文字/javascript。这会出现在HTML4.0规范,无论如何。

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

[编辑]多么有趣的 RFC 这一标准化的应用程序/javascript是2岁,但text/javascript仍然是更为常见。这是又一种情况下的定义胜过的标准?它也出现在 HTML5.

官方RFC义Javascript MIME Type是 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.
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top