Was ist die Javascript-MIME-Typ für das type-Attribut eines Script-Tag? [Duplikat]

StackOverflow https://stackoverflow.com/questions/189850

  •  06-07-2019
  •  | 
  •  

Frage

    

Diese Frage bereits eine Antwort hier:

         

Was ist der MIME Art von JavaScript?

Genauer gesagt, was ist das Richtige im Attribut „type“ eines Script-Tag zu setzen? application/x-javascript und text/javascript scheinen die wichtigsten Anwärter zu sein.

War es hilfreich?

Lösung

Dies ist ein häufiger Fehler. Der MIME-Typ für Javascript, wurde jahrelang nicht standardisiert. Es ist jetzt offiziell : " application / javascript ".

Die eigentliche Kicker hier ist, dass die meisten Browser das Attribut ohnehin nicht verwenden werden, zumindest nicht im Fall des Script-Tag. Sie tatsächlich in dem Paket peek und bestimmen die Art für sich selbst.

So lautet das Fazit ist, dass der type = „text / javascript“ tut nichts, so weit das Javascript betrifft, aber es ist Teil der Spezifikation sowohl für HTML 4 und XHTML 1.0 .

Andere Tipps

Weit draußen ist dies die erste Seite, die ich über das Thema mit irgendeinem Sinne darüber gefunden habe.

Meine kollektive Forschung schlägt vor:

  1. text/javascript als Keparo angegeben ist, muss in HTML4 und xhtml1 verwendet werden, wenn Sie es überprüfen möchten. Obwohl Browser ignorieren.
  2. application/javascript wird erwartet, dass der neue offizielle MIME-Typ sein, wenn sie alle einig, und wenn alles einholt.
  3. application/x-javascript (x Bedeutung nicht offiziell) ist der aktuelle Server-Seite MIME-Referenz für Javascript.
  4. Jeder erwartet, dass wie üblich, Microsoft etwas ganz andere weiter zu tun, wird darüber entscheiden, die Sache zu verwirren und Zeug.

Zusammenfassung: Vorerst, wenn Sie Ihre HTML wollen / xhtml in MSIE zu arbeiten und mit W3C validiert dann type="text/javascript" erklären. Wenn Sie Ihren Web-Server wollen wissen, dass Sie meinen Javascript dann application/x-javascript verwenden.

text / javascript

Ich glaube, IE nicht application / x-javascript akzeptieren

Festlegen der Skriptsprache

In einem Script-Tag würde ich text / javascript verwenden. Dies wird in der HTML 4.0-Spezifikation, sowieso.

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

[EDIT] Lustig, wie die RFC dass standardisierte auf application / javascript ist 2 Jahre alt, aber text / javascript ist noch häufiger. Ist das noch ein weiterer Fall von benutzerdefinierten triumphiert über Standards? Es scheint auch in HTML5 .

Die offizielle RFC, der die Javascript MIME-Typ definiert ist 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.
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top