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

xxb16uws  于 2023-01-19  发布在  Java
关注(0)|答案(5)|浏览(127)
    • 此问题在此处已有答案**:

When serving JavaScript files, is it better to use the application/javascript or application/x-javascript(6个答案)
七年前就关门了。
什么是MIME类型的javascript?
更具体地说,在脚本标记的"type"属性中放入什么是正确的?application/x-javascripttext/javascript似乎是主要的竞争者。

goqiplq2

goqiplq21#

这是一个常见的错误。javascript的MIME类型多年来没有标准化。现在它是officially:“应用程序/javascript"。
这里真实的的问题是大多数浏览器根本不会使用这个属性,至少在脚本标签的情况下不会,它们实际上是偷看包的内部并自己确定类型。
因此,底线是type=“text/javascript”对javascript没有任何作用,但它是HTML 4XHTML 1.0规范的一部分。

vsnjm48y

vsnjm48y2#

这是我找到的关于这个主题的第一页。
我的集体研究表明:

  1. Keparo说,如果你想验证text/javascript,就必须在html 4和xhtml 1中使用它,尽管浏览器会忽略它。
    1.如果每个人都同意并且一切都跟上的话,application/javascript有望成为新的官方MIME类型。
  2. application/x-javascript(x表示非官方)是当前javascript服务器端MIME引用。
    1.每个人都预计,像往常一样,微软将决定做一些完全不同的事情,以进一步混淆和事情。
    总结:现在,如果你想让你的html/xhtml在MSIE中工作,并通过W3C验证,那么就声明type="text/javascript",如果你想让你的web服务器知道你指的是javascript,那么就使用application/x-javascript
nzrxty8p

nzrxty8p3#

文本/javascript
我相信IE不接受application/x-javascript
指定脚本语言

ws51t4hk

ws51t4hk4#

在脚本标签中,我会使用text/javascript。无论如何,这会出现在the HTML 4.0 specification中。
有趣的是,基于application/javascript标准化的RFC是2006年的,但text/javascript仍然更常见。这是定制战胜标准的又一个例子吗?它也出现在HTML5中,可能是因为避免PNG图像的相同原因-与IE 5和6兼容。

szqfcxe2

szqfcxe25#

定义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.

相关问题