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

时间:2022-05-05 21:24:57

This question already has an answer here:

这个问题在这里已有答案:

What is the MIME type of javascript?

什么是javascript的MIME类型?

More specifically, what is the right thing to put in the "type" attribute of a script tag? application/x-javascript and text/javascript seem to be the main contenders.

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

5 个解决方案

#1


130  

This is a common mistake. The MIME type for javascript wasn't standardized for years. It's now officially: "application/javascript".

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

The real kicker here is that most browsers won't use that attribute anyway, at least not in the case of the script tag. They actually peek inside the packet and determine the type for themselves.

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

So the bottom line is that the type="text/javascript" doesn't do anything as far as the javascript is concerned, but it's part of the spec for both HTML 4 and XHTML 1.0.

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

#2


21  

Far out this is the first page I've found on the topic with any sense about it.

这是我在这个主题上找到的关于它的第一页。

My collective research suggests:

我的集体研究表明:

  1. text/javascript as Keparo stated must be used in html4 and xhtml1 if you want it to validate. Though browsers ignore it.
  2. 如果你想要验证,必须在html4和xhtml1中使用keparo所述的text / javascript。虽然浏览器忽略它。
  3. application/javascript is expected to be the new official MIME type if everyone agrees and when everything catches up.
  4. 如果每个人都同意并且当一切都赶上时,应用程序/ javascript应该是新的官方MIME类型。
  5. application/x-javascript (x meaning unofficial) is the current server side MIME reference for javascript.
  6. application / x-javascript(x表示非官方)是javascript的当前服务器端MIME引用。
  7. Everyone expects that as per usual, Microsoft will decide to do something completely different to further confuse and stuff up the matter.
  8. 每个人都希望,按照惯例,微软将决定做一些完全不同的事情,以进一步混淆和填补此事。

Summary: For now, if you want your html/xhtml to work in MSIE and validate with W3C then declare type="text/javascript". If you want your web server to know that you mean javascript then use application/x-javascript.

简介:目前,如果您希望html / xhtml在MSIE中工作并使用W3C进行验证,则声明type =“text / javascript”。如果您希望您的Web服务器知道您的意思是javascript,那么使用application / x-javascript。

#3


4  

text/javascript

文/ JavaScript的

I believe IE doesn't accept application/x-javascript

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

Specifying the scripting language

指定脚本语言

#4


2  

In a script tag I would use text/javascript. This appears in the HTML 4.0 specification, anyway.

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

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

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

[EDIT] Funny how the RFC that standardized on application/javascript is 2 years old, but text/javascript is still more common. Is this yet another case of custom triumphing over standards? It also appears in HTML5.

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

#5


1  

The official RFC that defines the Javascript MIME Type is RFC4329.

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

#1


130  

This is a common mistake. The MIME type for javascript wasn't standardized for years. It's now officially: "application/javascript".

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

The real kicker here is that most browsers won't use that attribute anyway, at least not in the case of the script tag. They actually peek inside the packet and determine the type for themselves.

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

So the bottom line is that the type="text/javascript" doesn't do anything as far as the javascript is concerned, but it's part of the spec for both HTML 4 and XHTML 1.0.

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

#2


21  

Far out this is the first page I've found on the topic with any sense about it.

这是我在这个主题上找到的关于它的第一页。

My collective research suggests:

我的集体研究表明:

  1. text/javascript as Keparo stated must be used in html4 and xhtml1 if you want it to validate. Though browsers ignore it.
  2. 如果你想要验证,必须在html4和xhtml1中使用keparo所述的text / javascript。虽然浏览器忽略它。
  3. application/javascript is expected to be the new official MIME type if everyone agrees and when everything catches up.
  4. 如果每个人都同意并且当一切都赶上时,应用程序/ javascript应该是新的官方MIME类型。
  5. application/x-javascript (x meaning unofficial) is the current server side MIME reference for javascript.
  6. application / x-javascript(x表示非官方)是javascript的当前服务器端MIME引用。
  7. Everyone expects that as per usual, Microsoft will decide to do something completely different to further confuse and stuff up the matter.
  8. 每个人都希望,按照惯例,微软将决定做一些完全不同的事情,以进一步混淆和填补此事。

Summary: For now, if you want your html/xhtml to work in MSIE and validate with W3C then declare type="text/javascript". If you want your web server to know that you mean javascript then use application/x-javascript.

简介:目前,如果您希望html / xhtml在MSIE中工作并使用W3C进行验证,则声明type =“text / javascript”。如果您希望您的Web服务器知道您的意思是javascript,那么使用application / x-javascript。

#3


4  

text/javascript

文/ JavaScript的

I believe IE doesn't accept application/x-javascript

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

Specifying the scripting language

指定脚本语言

#4


2  

In a script tag I would use text/javascript. This appears in the HTML 4.0 specification, anyway.

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

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

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

[EDIT] Funny how the RFC that standardized on application/javascript is 2 years old, but text/javascript is still more common. Is this yet another case of custom triumphing over standards? It also appears in HTML5.

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

#5


1  

The official RFC that defines the Javascript MIME Type is RFC4329.

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