代码之家  ›  专栏  ›  技术社区  ›  Craig McQueen

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

  •  124
  • Craig McQueen  · 技术社区  · 17 年前

    什么是 MIME javascript的类型?

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

    5 回复  |  直到 11 年前
        1
  •  133
  •   David Braun    11 年前

    这是一个常见的错误。javascript的MIME类型多年来一直没有标准化。就是现在 officially : " 应用程序/javascript ".

    这里真正的问题是,大多数浏览器无论如何都不会使用该属性,至少在script标签的情况下不会。他们实际上会窥探数据包内部,并自行确定类型。

    因此,最重要的是,就javascript而言,type=“text/javascript”没有任何作用,但它是两者规范的一部分 HTML 4 XHTML 1.0 .

        2
  •  21
  •   Timo Tijhof avalkab    11 年前

    这是我找到的关于这个话题的第一页,对它没有任何意义。

    我的集体研究表明:

    1. text/javascript 正如Keparo所说,如果你想验证它,就必须在html4和xhtml1中使用。尽管浏览器会忽略它。
    2. application/javascript 如果大家都同意,并且一切进展顺利,预计将成为新的官方MIME类型。
    3. application/x-javascript (x表示非官方)是当前javascript的服务器端MIME引用。
    4. 每个人都希望,像往常一样,微软将决定做一些完全不同的事情来进一步混淆和填塞这件事。

    摘要:目前,如果您希望您的html/xhtml在MSIE中工作并与W3C验证,请声明 type="text/javascript" .如果你想让你的web服务器知道你的意思是javascript,那么使用 应用程序/x-javascript .

        3
  •  4
  •   Morgan ARR Allen    17 年前

    text/javascript

    我认为IE不接受application/x-javascript

    Specifying the scripting language

        4
  •  2
  •   tvanfosson    17 年前

    在脚本标签中,我会使用 text/javascript 。这出现在 the HTML 4.0 specification 不管怎样。

    有趣的是 RFC 标准化 application/javascript 是2006年的,但是 text/javascript 更为常见。这是另一个习惯战胜标准的案例吗? 它也出现在 HTML5 这可能是因为避免使用PNG图像的原因——与IE 5和6兼容。

        5
  •  1
  •   BryanH Philipp Andreychev    13 年前

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