Qual è il tipo MIME javascript per l'attributo type di un tag script? [duplicare]

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

  •  06-07-2019
  •  | 
  •  

Domanda

    

Questa domanda ha già una risposta qui:

         

Che cos'è il tipo MIME di javascript?

Più specificamente, qual è la cosa giusta da inserire nel "tipo" attributo di un tag di script? application / x-javascript e text / javascript sembrano essere i principali contendenti.

È stato utile?

Soluzione

Questo è un errore comune. Il tipo MIME per javascript non è stato standardizzato per anni. Ora è ufficialmente : " application / javascript " ;.

Il vero kicker qui è che la maggior parte dei browser non utilizzerà comunque quell'attributo, almeno non nel caso del tag script. In realtà fanno capolino all'interno del pacchetto e determinano il tipo da soli.

Quindi la linea di fondo è che type = " text / javascript " non fa nulla per quanto riguarda javascript, ma fa parte delle specifiche sia per HTML 4 che XHTML 1.0 .

Altri suggerimenti

Di gran lunga questa è la prima pagina che ho trovato sull'argomento con qualche senso al riguardo.

La mia ricerca collettiva suggerisce:

  1. text / javascript come indicato da Keparo deve essere utilizzato in html4 e xhtml1 se si desidera che venga convalidato. Sebbene i browser lo ignorino.
  2. application / javascript dovrebbe essere il nuovo tipo MIME ufficiale se tutti sono d'accordo e quando tutto raggiunge.
  3. application / x-javascript (x significa non ufficiale) è l'attuale riferimento MIME lato server per javascript.
  4. Tutti si aspettano che, come al solito, Microsoft decida di fare qualcosa di completamente diverso per confondere ulteriormente e risolvere il problema.

Riepilogo: per ora, se vuoi che il tuo html / xhtml funzioni in MSIE e convalidi con W3C, dichiara type = " text / javascript " . Se vuoi che il tuo server web sappia che intendi javascript, usa application / x-javascript .

text / javascript

Credo che IE non accetti application / x-javascript

Specifica del linguaggio di scripting

In un tag script userei text / javascript. Questo appare comunque nelle specifiche HTML 4.0.

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

[EDIT] Divertente come il RFC quello standardizzato su application / javascript ha 2 anni, ma text / javascript è ancora più comune. È ancora un altro caso di trionfo personalizzato rispetto agli standard? Appare anche in HTML5 .

La RFC ufficiale che definisce il tipo MIME Javascript è 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.
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top